Hi,
Thank you very much for this useful library.
I have a request.
Now:
loadXml("<xml><tag1 /></xml>").toString()
returns "<xml><tag1></tag1></xml>"
What I hope is:
loadXml("<xml><tag1 /></xml>").toString()
returns "<xml><tag1 /></xml>"
I understood that we should to define new element_type like
''DOMNode.EMPTY_ELEMENT_NODE = 14;
But it is hard for me now, so I made a patch for quick and dirty hack.
#This includes MAGIC_NUMBER(isEmptyElement="true")...
Thanks!
Kah_Kah
--- xmlw3cdom.js.org 2007-12-20 10:41:55.000000000 +0900
+++ xmlw3cdom.js 2007-12-26 14:45:16.000000000 +0900
@@ -416,6 +416,12 @@
iAttr.setValue(p.getAttributeValue(i)); // set Attribute value
iNode.setAttributeNode(iAttr); // attach Attribute to Element
}
+ /*
+ * Keep EMPTY_ELEMENT type
+ */
+ iAttr = doc.createAttribute("isEmptyElement");
+ iAttr.setValue("true");
+ iNode.setAttributeNode(iAttr);
}
else { // Namespace Aware
// create element (with empty namespaceURI,
@@ -459,6 +465,13 @@
}
}
}
+
+ /*
+ * Keep EMPTY_ELEMENT type
+ */
+ iAttr = doc.createAttribute("isEmptyElement");
+ iAttr.setValue("true");
+ iNode.setAttributeNode(iAttr);
// resolve namespaceURIs for this Element
if (iNode._namespaces.getNamedItem(iNode.prefix)) {
@@ -3328,9 +3341,14 @@
if (attrs.length > 0) attrs = " "+ attrs;
// serialize this Element
- ret += "<" + this.nodeName + ns + attrs +">";
- ret += this.childNodes.toString();;
- ret += "</" + this.nodeName+">";
+ if (attrs.indexOf("isEmptyElement") >= 0) {
+ attrs = attrs.replace(/ isEmptyElement=\"true\"/,"");
+ ret += "<" + this.nodeName + ns + attrs +" />";
+ } else {
+ ret += "<" + this.nodeName + ns + attrs +">";
+ ret += this.childNodes.toString();
+ ret += "</" + this.nodeName+">";
+ }
return ret;
}
|