XmlTextWriter Problem

  • Thread starter Thread starter babylon
  • Start date Start date
B

babylon

I have an XML tag that may contain optional child element:
i.e.
<mytag myattribute="abc">
<othertag>
...
</othertag>
</mytag>
or just
<mytag myattribute="abc"></mytag>
however, if i do
WriteStartElement("mytag");
WriteAttributeString("myattribute", "abc");
WriteEndElement(); // mytag
it would become:
<mytag myattribute="abc" />
...
can i specify it to become
<mytag myattribute="abc"></mytag>
??

as when i do
ReadStartElement("mytag")
XXXX
ReadEndElement(); // This will fail if it encounter <mytag myattribute="abc"
/ >

but remember that <mytag> may contain sub elements...
...

please help!
 
Hi,
Use WriteFullEndElement to write closed (empty) elements (like this <mytag
myattribute="abc"/>).
During read, use IsStartElement method and IsEmptyElement property to avoid
ReadEndElement failure.
--
Andrew Gnenny
pulsar2003@/no-spam/email.ru (Please remove /no-spam/ for reply)
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
 
it works!
thx!!

Andrew Gnenny said:
Hi,
Use WriteFullEndElement to write closed (empty) elements (like this <mytag
myattribute="abc"/>).
During read, use IsStartElement method and IsEmptyElement property to avoid
ReadEndElement failure.
--
Andrew Gnenny
pulsar2003@/no-spam/email.ru (Please remove /no-spam/ for reply)
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
 
Back
Top