We help IT Professionals succeed at work.

How can i separate tags in a xml file

Medium Priority
341 Views
Last Modified: 2012-05-06
I have a code that create an xml file but when this code receive an empty string aperars like this  <Label /> and i need this structure <Label></Label> how can i get this? I have this code:
xWriter.WriteStartElement("Label")
xWriter.WriteString("")
xWriter.WriteFullEndElement()
Comment
Watch Question

CERTIFIED EXPERT
Commented:
Has to be more like this....
With xWriter
      .WriteStartDocument()
     .WriteStartElement("MyMainTag")
      WriteElementString("Label", "")
     .WriteEndElement()
    .Flush()
   .Close()
End With

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
The suggested solution does not work for what I need. For a business requirement, I need an element like this: <ProviderID></ProviderID>. Following the suggested solution, I tried:
            writer.WriteStartElement("PID");
            writer.WriteElementString("ProviderID", String.Empty);
            writer.WriteFullEndElement();

This gives me either an extra tag I don't want:
<PID>
  <ProviderID />
</PID>

Every other solution I've tried like the following gives me <ProviderID />.
            writer.WriteStartElement("ProviderID");
            writer.WriteString(String.Empty);
            writer.WriteFullEndElement();

It appears that WriteEndElement() does not provide the single functionality it is designed to provide.

Does anyone know how to accomplish this?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.