473,503 Members | 1,638 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML formatting question

Hello all,

After I've constructed an XmlDocument object composed of XmlNodes, I
send the actual InnerXml contents to a server where my XML is processed.
However, elements that have no InnerText end up looking like this:

<PartMessage MessageText="INVENTORY REQUEST" MessageKeyword="REASON" />

however, I need the closing tag to be fully expanded as such:

<PartMessage MessageText="INVENTORY REQUEST"
MessageKeyword="REASON"></PartMessage>

Is there a method or property for either the XmlDocument or the
individual XmlNode objects that will format my text the way I've
described? Thank you much!

Jason

Nov 12 '05 #1
6 1937
My mistake, I meant to say my document is composed of XmlElements as
opposed to XmlNodes.

Thanks!

Jason Hurder wrote:
Hello all,

After I've constructed an XmlDocument object composed of XmlNodes, I
send the actual InnerXml contents to a server where my XML is processed.
However, elements that have no InnerText end up looking like this:

<PartMessage MessageText="INVENTORY REQUEST" MessageKeyword="REASON" />

however, I need the closing tag to be fully expanded as such:

<PartMessage MessageText="INVENTORY REQUEST"
MessageKeyword="REASON"></PartMessage>

Is there a method or property for either the XmlDocument or the
individual XmlNode objects that will format my text the way I've
described? Thank you much!

Jason


Nov 12 '05 #2
I would like to know why you need to format the XML in that way.
Is it really necessary?
Although i am not sure, i do not think there is a way to make XmlNode format
the xml as you want.
You could place a character in the node, like a space, to force the format
you want.
You could also achieve that format by using
System.Xml.XmlWriter(XmlTextWriter), using
the WriteRaw method to manually compose the source of the XML node.
--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Jason Hurder" <jhurder@spam_me_not.fastpicsystems.com> wrote in message
news:uN**************@TK2MSFTNGP15.phx.gbl...
Hello all,

After I've constructed an XmlDocument object composed of XmlNodes, I send
the actual InnerXml contents to a server where my XML is processed.
However, elements that have no InnerText end up looking like this:

<PartMessage MessageText="INVENTORY REQUEST" MessageKeyword="REASON" />

however, I need the closing tag to be fully expanded as such:

<PartMessage MessageText="INVENTORY REQUEST"
MessageKeyword="REASON"></PartMessage>

Is there a method or property for either the XmlDocument or the individual
XmlNode objects that will format my text the way I've described? Thank you
much!

Jason

Nov 12 '05 #3


Jason Hurder wrote:

After I've constructed an XmlDocument object composed of XmlNodes, I
send the actual InnerXml contents to a server where my XML is processed.
However, elements that have no InnerText end up looking like this:

<PartMessage MessageText="INVENTORY REQUEST" MessageKeyword="REASON" />

however, I need the closing tag to be fully expanded as such:

<PartMessage MessageText="INVENTORY REQUEST"
MessageKeyword="REASON"></PartMessage>

Is there a method or property for either the XmlDocument or the
individual XmlNode objects that will format my text the way I've
described?


Yes, within .NET for XmlElement objects you can set
element.IsEmpty = false;
and then the serialization is done in the
<tag></tag>
for.
Here is a short example

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(@"<gods>
<god name=""Kibo"" />
<god name=""Xibo"" />
</gods>");
Console.WriteLine("Serialized XML: {0}", xmlDocument.OuterXml);
foreach (XmlNode node in xmlDocument.GetElementsByTagName("god")) {
(node as XmlElement).IsEmpty = false;
}
Console.WriteLine("Serialized XML: {0}", xmlDocument.OuterXml);
}

Output is

Serialized XML: <gods><god name="Kibo" /><god name="Xibo" /></gods>
Serialized XML: <gods><god name="Kibo"></god><god name="Xibo"></god></gods>

so that is what you are looking for I think.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #4
Martin - thank you very much, that did the trick.

One other question - is it possible to format the InnerXml property to
include insignificant white space? So instead of this:

<SrcMeta Name="StoreNo" Value="02" /><SrcMeta Name="SysID"
Value="183161305750757" /><SrcMeta Name="SysType" Value="ERA" /><SrcMeta
Name="BranchNo" Value="01" />

I end up with this?

<SrcMeta Name="StoreNo" Value="02" />
<SrcMeta Name="SysID" Value="183161305750757" />
<SrcMeta Name="SysType" Value="ERA" />
<SrcMeta Name="BranchNo" Value="01" />

This isn't necessary, just makes it a whole lot easier to read in
notepad. Thanks!

Martin Honnen wrote:


Jason Hurder wrote:

After I've constructed an XmlDocument object composed of XmlNodes, I
send the actual InnerXml contents to a server where my XML is
processed. However, elements that have no InnerText end up looking
like this:

<PartMessage MessageText="INVENTORY REQUEST" MessageKeyword="REASON" />

however, I need the closing tag to be fully expanded as such:

<PartMessage MessageText="INVENTORY REQUEST"
MessageKeyword="REASON"></PartMessage>

Is there a method or property for either the XmlDocument or the
individual XmlNode objects that will format my text the way I've
described?

Yes, within .NET for XmlElement objects you can set
element.IsEmpty = false;
and then the serialization is done in the
<tag></tag>
for.
Here is a short example

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(@"<gods>
<god name=""Kibo"" />
<god name=""Xibo"" />
</gods>");
Console.WriteLine("Serialized XML: {0}", xmlDocument.OuterXml);
foreach (XmlNode node in xmlDocument.GetElementsByTagName("god")) {
(node as XmlElement).IsEmpty = false;
}
Console.WriteLine("Serialized XML: {0}", xmlDocument.OuterXml);
}

Output is

Serialized XML: <gods><god name="Kibo" /><god name="Xibo" /></gods>
Serialized XML: <gods><god name="Kibo"></god><god name="Xibo"></god></gods>

so that is what you are looking for I think.


Nov 12 '05 #5


Jason Hurder wrote:

One other question - is it possible to format the InnerXml property to
include insignificant white space?


You can set
xmlDocument.PreserveWhitespace = true;
before you call Load or LoadXml and then white space should be preserved.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #6
hi, I am puffy ...i saw ur post in msdn discussion on how to format a XML
document style..i am now doing my project paper in University which need me
to do something like yours in the discussion...can i have a look on your
partial source code for what you asking in the discussion?there is a post
that u say u need to preserved some white space in your xml doc...and then
you post a data like:
<SrcMeta Name="StoreNo" Value="02" />
<SrcMeta Name="SysID" Value="183161305750757" />
<SrcMeta Name="SysType" Value="ERA" />
<SrcMeta Name="BranchNo" Value="01" />
how you do it?..are u loading the data from a database?or from a source with
different database into the xmldocument write?..

ur help is vr much appreciated.....!!!

"Jason Hurder" wrote:
Martin - thank you very much, that did the trick.

One other question - is it possible to format the InnerXml property to
include insignificant white space? So instead of this:

<SrcMeta Name="StoreNo" Value="02" /><SrcMeta Name="SysID"
Value="183161305750757" /><SrcMeta Name="SysType" Value="ERA" /><SrcMeta
Name="BranchNo" Value="01" />

I end up with this?

<SrcMeta Name="StoreNo" Value="02" />
<SrcMeta Name="SysID" Value="183161305750757" />
<SrcMeta Name="SysType" Value="ERA" />
<SrcMeta Name="BranchNo" Value="01" />

This isn't necessary, just makes it a whole lot easier to read in
notepad. Thanks!

Martin Honnen wrote:


Jason Hurder wrote:

After I've constructed an XmlDocument object composed of XmlNodes, I
send the actual InnerXml contents to a server where my XML is
processed. However, elements that have no InnerText end up looking
like this:

<PartMessage MessageText="INVENTORY REQUEST" MessageKeyword="REASON" />

however, I need the closing tag to be fully expanded as such:

<PartMessage MessageText="INVENTORY REQUEST"
MessageKeyword="REASON"></PartMessage>

Is there a method or property for either the XmlDocument or the
individual XmlNode objects that will format my text the way I've
described?

Yes, within .NET for XmlElement objects you can set
element.IsEmpty = false;
and then the serialization is done in the
<tag></tag>
for.
Here is a short example

XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(@"<gods>
<god name=""Kibo"" />
<god name=""Xibo"" />
</gods>");
Console.WriteLine("Serialized XML: {0}", xmlDocument.OuterXml);
foreach (XmlNode node in xmlDocument.GetElementsByTagName("god")) {
(node as XmlElement).IsEmpty = false;
}
Console.WriteLine("Serialized XML: {0}", xmlDocument.OuterXml);
}

Output is

Serialized XML: <gods><god name="Kibo" /><god name="Xibo" /></gods>
Serialized XML: <gods><god name="Kibo"></god><god name="Xibo"></god></gods>

so that is what you are looking for I think.


Nov 12 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5918
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
2
1925
by: Colleyville Alan | last post by:
I am using Access and have embedded the ActiveX control Formula One that came with Office 2000. (ver 3.04). I have created and formatted a spreadsheet and now I want to copy the info with...
4
4117
by: DBQueen | last post by:
I have a subform which is in Continuous Forms view. I have added a button to the bottom of the page to move to the next record using the button wizard (result: DoCmd.GoToRecord , , acNext). I...
4
2066
by: Dave Brydon | last post by:
Access 2003 I have a combo box in my personnel table, which draws its data from a trade code table; the original field in the code table, is numeric, Long Integer, and formatted with 5 zero's . ...
4
3220
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
4
2606
by: Nalaka | last post by:
Hi, I have two questions about gridViews. 1. How can I intercept the row/column values at loading to change values? 2. After I update a row (using default update functionality), how can I...
25
2664
by: mdh | last post by:
Hi Group, Not looking for an answer, but more of an explanation. Thinking back to those heady days when you had the time to do them, may I ask this. Exercise 1-22 asks for a program to "fold"...
1
1437
by: Russell Mangel | last post by:
I am using VS2005. When I paste source code into the code window, VS2005 formats like the following: public MsgRecipientReader() : base() { }
7
3083
by: L. Scott M. | last post by:
Have a quick simple question: dim x as string x = "1234567890" ------------------------------------------------------- VB 6 dim y as string
10
8580
by: Lyn | last post by:
Hi, I would like to make a bound text box not visible if it is empty (not just disable it). This option is not available from the standard conditional formatting feature (at least, not that I can...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.