XmlTextWriter end tag question

Posted on 2006-05-18
Last Modified: 2013-11-19

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:

           <foldername />
           <folderID />
<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?

Question by:Tim_Heldberg
    LVL 44

    Expert Comment

    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
    LVL 4

    Author Comment

    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.


    The same thing is being produced whether name has a value or an empty string.
    LVL 44

    Accepted Solution

    LVL 4

    Author Comment

    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.
    LVL 44

    Expert Comment

    ah so you already was using the correct approach, maybe you can bill microsoft for some wasted time :)

    thanks for the grade

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now