469,352 Members | 2,107 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

Removing self-closing tags in XMLDocument.Save

Hi,

I have a VB.NET (VS2005, .NET 2.0) application producing an XML file which
is then used by a third-party product. It turns out the latter doesn't like
self-closing tags (i.e. it would rather see <CardNo></CardNothan <CardNo
/>).

Is there a simple way to tell the XMLDocument to use the "traditional" way
of showing an empty tag instead of always saving self-closing tags?

Many thanks,

David Cartwright
Jun 4 '07 #1
4 10479
David Cartwright wrote:
I have a VB.NET (VS2005, .NET 2.0) application producing an XML file which
is then used by a third-party product. It turns out the latter doesn't like
self-closing tags (i.e. it would rather see <CardNo></CardNothan <CardNo
/>).

Is there a simple way to tell the XMLDocument to use the "traditional" way
of showing an empty tag instead of always saving self-closing tags?
With XML <CardNo></CardNohas the same semantics as <CardNo/or
<CardNo /so you should rather blame that third party tool to not
conform to the XML specification.

As for trying to change your XML with .NET tools, how exactly do you
create the XML? If you use an XmlWriter then use WriteFullEndElement
<http://msdn2.microsoft.com/en-us/library/system.xml.xmlwriter.writefullendelement.aspx>
as that way you can ensure the <CardNo></CardNosyntax.

If you are using XmlDocument/XmlElement then there is a property IsEmpty
that you can set to false to get the form <CardNo></CardNo>.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 4 '07 #2
"Martin Honnen" <ma*******@yahoo.dewrote in message
news:ua****************@TK2MSFTNGP06.phx.gbl...
With XML <CardNo></CardNohas the same semantics as <CardNo/or <CardNo
/so you should rather blame that third party tool to not conform to the
XML specification.
Yup. But they're so useless that if I ask them to fix their end, it'll be at
least Christmas ... and not necessarily the one in 2007 either.
As for trying to change your XML with .NET tools, how exactly do you
create the XML? If you are using XmlDocument/XmlElement then there is a
property IsEmpty that you can set to false to get the form
<CardNo></CardNo>.
I have a load of node creations looking like:
revXML.DocumentElement.AppendChild(revXML.ImportNo de(tmpNode, True))
.... as what I'm doing is pulling nodes out of an input XML document and then
streaming them out to two others.

David C
Jun 4 '07 #3
David Cartwright wrote:
>As for trying to change your XML with .NET tools, how exactly do you
create the XML? If you are using XmlDocument/XmlElement then there is a
property IsEmpty that you can set to false to get the form
<CardNo></CardNo>.

I have a load of node creations looking like:
revXML.DocumentElement.AppendChild(revXML.ImportNo de(tmpNode, True))
... as what I'm doing is pulling nodes out of an input XML document and then
streaming them out to two others.
Then loop through
foreach (XmlElement element in revXML.SelectNodes("//*[not(node())]"))
and set the IsEmpty property of those XmlElement instances to false.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 4 '07 #4
"Martin Honnen" <ma*******@yahoo.dewrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
Then loop through
foreach (XmlElement element in revXML.SelectNodes("//*[not(node())]"))
and set the IsEmpty property of those XmlElement instances to false.
That's great - thanks so much.

David C
Jun 4 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Brent W. Hughes | last post: by
16 posts views Thread by qwweeeit | last post: by
11 posts views Thread by Steven D'Aprano | last post: by
2 posts views Thread by Svenn Bjerkem | last post: by
3 posts views Thread by Kilicaslan Fatih | last post: by
3 posts views Thread by agupta0318 | last post: by
m6s
3 posts views Thread by m6s | last post: by
11 posts views Thread by George Sakkis | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.