Link to home
Start Free TrialLog in
Avatar of Tim_Heldberg
Tim_Heldberg

asked on

XmlTextWriter end tag question

Hello,

I am working on an app that uses the XmlTextWriter class to create an XML doc.  The problem is that my xml doc will have several nodes like this:

<folders>
      <folder>
           <foldername />
           <folderID />
      <folder
      ...
<folders />

This is all fine, when the properties of the folder (name, ID) are empty, I want the xml tag to look like it does above  '<foldername />'.  But if there are no folders in the folder collection, I want it to be written like this:

<folders></folders>, and I can only seem to get it to write it like this <folders />.

Does anyone know how to force this seperate ending tag?

Thanks
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Hi Tim_Heldberg,

not sure how the code looks like,  but when adding elements you could look into the WriteStartElement and WriteEndElement to use them explicitly when there are no values for a folders node

hope this helps a bit
bruintje
Avatar of Tim_Heldberg
Tim_Heldberg

ASKER

I have been using the calls to WriteStart and WriteEnd, that is what is actually what is producing what I have shown above.  Here is a code snip.

            jobScript.WriteStartElement(DescriptorNameNodeName);
            jobScript.WriteString(descriptor.Name);
            jobScript.WriteEndElement();

The same thing is being produced whether name has a value or an empty string.
ASKER CERTIFIED SOLUTION
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the help.  I had actually been trying that call and I thought I was getting the same result.  The thing is that it was actually working right, but when I was viewing the xml in internet explorer, it was collapsing the empty nodes into the single tag.
ah so you already was using the correct approach, maybe you can bill microsoft for some wasted time :)

thanks for the grade