I'm trying to create the following element nodetree:
<v:custProps>
<v:cp v:nameU="Cost">
</v:custProps>
with:
newCustprop = document.createElement("v:custProps");
newcp = document.createElement("v:cp");
newcp.setAttribute("v:nameU", "Cost");
newCustprop.appendChild(newcp);
However, document.createElement("v:custProps")
generates <v:custprops>
as opposed to <v:custProps>
. Is there anyway to escape this parsing?
Edit 1:
I'm currently reading this article on nodename case sensitivity. It's slightly irrelevant to my problem though because my code is unparsed with <![CDATA]]>
and I'd rather not use .innerHTML
.
You need to use
createElementNS()
/setAttributeNS()
and provide the namespace, not only the alias/prefix. The example usesurn:v
as namespace.xml:
It's not recommended to use
document.createElement
for qualified names. See if thedocument.createElementNS
can better serve your purposes.