M
marfi95
I have an xml file that I want to maintain the whitespace on and
spacing between my sections. I have something like this.
<!-- Comment lines A -->
<!-- Comment lines A -->
<A>
<B>test</B>
<B>test1</B>
<B>test2</B>
</A>
blank line here
<!-- Comment lines B -->
<!-- Comment lines B -->
<C>
<B>test</B>
<B>test1</B>
<B>test2</B>
</C>
I have written a little editor for users to maintain the various xml.
Everything works great except I want to keep the blank lines between my
groups. I have preservewhitespace set to True when I load/save the
document, but when I save it back out after replacing the edited node,
I lose formatting. This is what I end up with if <C> is replaced. If
I take out the preservewhitespace, I lose the blank lines in the xml
file.
<!-- Comment lines A -->
<!-- Comment lines A -->
<A>
<B>test</B>
<B>test1</B>
<B>test2</B>
</A>
blank line here
<!-- Comment lines B-->
<!-- Comment lines B-->
<C><B>test</B><B>test1</B><B>test2</B></C>
Here is the code I use to write the file back out.
Dim writer As XmlTextWriter = New
XmlTextWriter(_mWorkingXMLFileName, Nothing)
writer.Formatting = Formatting.Indented
_mWorkingXMLDoc.PreserveWhitespace = True
_mWorkingXMLDoc.Save(writer)
writer.Flush()
writer.Close()
I thought the combination of formatting.indented and whitespace=true
would work, but they seem to counteract each other. Any ideas ?
When I build my replacement XML, its just a string, then loaded into
another document. Do I just need CRLF in the proper locations ?
One other thing, when I write out the new xml, I want to verify that
the comments above the node exist, otherwise I want to create them.
How can I go about verifying this or inserting new ones in the proper
location ?
Many thanks !
Mark
spacing between my sections. I have something like this.
<!-- Comment lines A -->
<!-- Comment lines A -->
<A>
<B>test</B>
<B>test1</B>
<B>test2</B>
</A>
blank line here
<!-- Comment lines B -->
<!-- Comment lines B -->
<C>
<B>test</B>
<B>test1</B>
<B>test2</B>
</C>
I have written a little editor for users to maintain the various xml.
Everything works great except I want to keep the blank lines between my
groups. I have preservewhitespace set to True when I load/save the
document, but when I save it back out after replacing the edited node,
I lose formatting. This is what I end up with if <C> is replaced. If
I take out the preservewhitespace, I lose the blank lines in the xml
file.
<!-- Comment lines A -->
<!-- Comment lines A -->
<A>
<B>test</B>
<B>test1</B>
<B>test2</B>
</A>
blank line here
<!-- Comment lines B-->
<!-- Comment lines B-->
<C><B>test</B><B>test1</B><B>test2</B></C>
Here is the code I use to write the file back out.
Dim writer As XmlTextWriter = New
XmlTextWriter(_mWorkingXMLFileName, Nothing)
writer.Formatting = Formatting.Indented
_mWorkingXMLDoc.PreserveWhitespace = True
_mWorkingXMLDoc.Save(writer)
writer.Flush()
writer.Close()
I thought the combination of formatting.indented and whitespace=true
would work, but they seem to counteract each other. Any ideas ?
When I build my replacement XML, its just a string, then loaded into
another document. Do I just need CRLF in the proper locations ?
One other thing, when I write out the new xml, I want to verify that
the comments above the node exist, otherwise I want to create them.
How can I go about verifying this or inserting new ones in the proper
location ?
Many thanks !
Mark