- }
-
- var tagName = self._join(nsData.prefix, node.getAttribute('x-node'));
-
- /* retrieve attributes */
- var attributeIDs = [];
- for (var i = 0; i < node.attributes.length; i++) {
- var attr = node.attributes.item(i);
-
- // check if name starts with "x-attr-name"
- var m = attr.name.match(XATTR_RE);
- if (m !== null)
- attributeIDs.push(m[1]);
- };
-
- /* print out */
-
- self.result += '<' + tagName;
-
- $.each(attributeIDs, function() {
- var nsData = self._assignNamespace(node.getAttribute('x-attr-ns-'+this));
-
- if(nsData.fresh) {
- newNamespaces.push(nsData);
- self.stack.push({
- "type": NS_END,
- "namespace": nsData
- });
- };
-
- self.result += ' ' + self._join(nsData.prefix, node.getAttribute('x-attr-name-'+this));
- self.result += '="'+node.getAttribute('x-attr-value-'+this) +'"';
- });
+ }
+
+ var tagName = self._join(nsData.prefix, node.getAttribute('x-node'));
+
+ /* retrieve attributes */
+ var attributeIDs = [];
+ var attributes = [];
+ for (var i = 0; i < node.attributes.length; i++) {
+ var attr = node.attributes.item(i);
+
+ m = attr.name.match(XATTR_KNOWN_RE);
+ if (m !== null) {
+ prefix = m[1];
+ let tag = m[2];
+ attributes.push([
+ NS_PREFIXES[prefix],
+ tag,
+ attr.value
+ ]);
+ } else {
+ // check if name starts with "x-attr-name"
+ var m = attr.name.match(XATTR_RE);
+ if (m !== null) {
+ attributeIDs.push(m[1]);
+ }
+ }
+ }
+
+ /* print out */
+
+ self.result += '<' + tagName;
+
+ function writeAttr(ns, tag, value) {
+ if (ns) {
+ var nsData = self._assignNamespace(ns);
+ if(nsData.fresh) {
+ newNamespaces.push(nsData);
+ self.stack.push({
+ "type": NS_END,
+ "namespace": nsData
+ });
+ };
+ tag = self._join(nsData.prefix, tag);
+ }
+
+ self.result += ' ' + tag;
+ self.result += '="' + value.replace(/&/g, '&').replace(/"/g, '"') + '"';
+ }
+
+ $.each(attributes, function() {
+ writeAttr(
+ this[0], this[1], this[2]
+ );
+ });
+
+ $.each(attributeIDs, function() {
+ writeAttr(
+ node.getAttribute('x-attr-ns-'+this),
+ node.getAttribute('x-attr-name-'+this),
+ node.getAttribute('x-attr-value-'+this)
+ );
+ });