Open microshine opened 6 years ago
Wouldn't a second xmlns:p2
(on the p2:fourth element) be redundant, here?
Wouldn't a second
xmlns:p2
(on the p2:fourth element) be redundant, here?
No, because that namespace declaration applies only to the second
element and any descendants.
https://www.w3.org/TR/xml-names/#scoping
Oh for some reason I was reading that completely backwards; yeah, the specified XMLDOM output isn't correct.
I found that commented code
https://github.com/jindw/xmldom/blob/master/dom.js#L1042-L1043
If uncomment that code it works fine
const doc = new DOMImplementation().createDocument(null, "root");
doc.documentElement.appendChild(doc.createElement("child"));
const signature1 = doc.createElementNS("https://signature.com", "Signature");
doc.documentElement.appendChild(signature1);
const signature2 = doc.createElementNS("https://signature.com", "Signature");
doc.documentElement.appendChild(signature2);
const xml = new XMLSerializer().serializeToString(doc);
console.log(xml);
// Output
// <root>
// <child/>
// <Signature xmlns="https://signature.com"/>
// <Signature xmlns="https://signature.com"/>
// </root>
const doc = new DOMImplementation().createDocument(null, "root");
const p1First = doc.createElementNS("http//first.namespace.com", "p1:first");
const p2Second = doc.createElementNS("http//second.namespace.com", "p2:second");
const p1Third = doc.createElementNS("http//first.namespace.com", "p1:third");
const p2Fourth = doc.createElementNS("http//second.namespace.com", "p2:fourth");
doc.documentElement.appendChild(p1First);
p1First.appendChild(p2Second)
p1First.appendChild(p1Third)
p1Third.appendChild(p2Fourth)
const xml = new XMLSerializer().serializeToString(doc);
console.log(xml);
// Output
// <root>
// <p1:first xmlns:p1="http//first.namespace.com">
// <p2:second xmlns:p2="http//second.namespace.com"/>
// <p1:third>
// <p2:fourth xmlns:p2="http//second.namespace.com"/>
// </p1:third>
// </p1:first>
// </root>
I use this app to generate XML document.
fourth
element in generated XML doesn't havexmlns:p2="http//second.namespace.com"
XMLDOM output:
Chrome output: