Problem about xml

  • Thread starter Thread starter Ray
  • Start date Start date
R

Ray

Dear all,
I am using XmlTextWriter for writing the xml file. The code is as follow:

Dim test As XmlTextWriter = Nothing
Dim UTF8 As New UTF8Encoding
test = New XmlTextWriter("C:\abcd.xml", UTF8)
With test
.Formatting = Formatting.Indented
.Indentation = 4
.IndentChar = " "
.WriteStartDocument()
.WriteDocType("SOGenericInterchange", Nothing,
"SOGenericInterchange.dtd", Nothing)
.WriteStartElement("a")
.WriteElementString("abc", "")
.WriteEndElement()
.Close()
End With

The xml file output will be as follow:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE SOGenericInterchange SYSTEM "SOGenericInterchange.dtd">
<a>
<abc /> <---- a space appears behind abc
</a>

The problem is that a space appears behind abc. I do not need a space
behind abc. How can I solve the problem?

Please help.
Thanks a lot,
Ray
 
Ray,
VS is not adding any additional spaces to your document. I used the code you
provided and got the results you intended. Are you using IE to view your
output? It appears that its' style sheet is adding the extra whitespace
chars. Change your IndentChar to something other than a space to see what I
mean. Open the results as you were before, then open it in notepad.
 
Back
Top