[ASP/VBscript] Creating empty XML elements

  • Thread starter Marja Ribbers-de Vroed
  • Start date
M

Marja Ribbers-de Vroed

Hi,

I'm using MSXML2.DOMDocument.4.0 to create an XML document on-the-fly.

Everything is going great except that at some point I need to create an empty XML element with a start and an end tag, not only an end tag.
Eg. I need to create <Signature></Signature> instead of <Signature />

However, MSXML2.DOMDocument.4.0 refuses to create the empty element with a start and an end tag.
It insists on creating only the closing end tag, even if I try to set text value for the element to "".

I've tried
Set l_oElement = s_oXML.createNode(1, "Signature", "")
l_oElement.text = ""

and I've tried
Set l_oElement = s_oXML.createNode(1, "Signature", "")
Set l_oNodeText = s_oXML.createTextNode("")
l_oElement.appendChild(l_oNodeText)

but it doesn't work like I need it to.

How can I create an empty XML element like <Signature></Signature>?
 
M

Marja Ribbers-de Vroed

Never mind, I solved it.

's_oXML.xml' does output empty elements the way I need them.
Only 's_oXML.save' that doesn't do it that way.

Regards, Marja
 
G

Gerry Hickman

Marja said:
Everything is going great except that at some point I need to create an empty XML element with a start and an end tag, not only an end tag.
Eg. I need to create <Signature></Signature> instead of <Signature />
I've tried
Set l_oElement = s_oXML.createNode(1, "Signature", "")
l_oElement.text = ""

Have you tried oXmlDoc.createElement("someName") and appending it,
instead of using createNode()

I'm pretty sure createElement() allows you to create empty elements.
 
M

Marja Ribbers-de Vroed

Have you tried oXmlDoc.createElement("someName") and appending it,
instead of using createNode()

I'm pretty sure createElement() allows you to create empty elements.


Thanks Gerry, but I had already tried that, and s_oXML.createNode(1, "Signature", "") had the same effect as s)oXML..createElement("Signature")

But it turned out that s_oXML.xml worked the way I want (a start and an end tag without a text in between), whereas s_oXML.save replaces the empty elements with only an empty element tag.
Using s_oXML is fine for my purpose.
 
G

Gerry Hickman

Marja said:
Thanks Gerry, but I had already tried that, and s_oXML.createNode(1, "Signature", "") had the same effect as s)oXML..createElement("Signature")

But it turned out that s_oXML.xml worked the way I want (a start and an end tag without a text in between), whereas s_oXML.save replaces the empty elements with only an empty element tag.
Using s_oXML is fine for my purpose.

OK I understand now; I thought you were saying you were unable to create
an empty element full stop, but you are able create an empty element,
but you don't like the way it's formatted as in

<Signature />

instead of

<Signature></Signature>

As far as I know, the former is the "official" way to write out an empty
element so that would explain why MSXML does it that way. It's not
usually an issue because once you add an attribute or some data it will
change it to the latter notation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top