Generate XML document - format issue

michaelX

New member
Joined
Mar 30, 2006
Messages
2
Location
Perth WA
Programming Experience
10+
Having a bit of bother generating XML in the format I require, I am trying to produce a application for a .NET CE device, were users enter in dispatch info and then scan bar codes of items and apply them to a delivery docket , I am trying to out the file in XML, how ever I am failing to get the correct format of the document correct, can any one assist me?


Currently generated XML document as generated from the code below:


HTML:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> 
<dispatch>
- <item>
<estamp>30-03-2006</estamp> 
<dispatcher>h</dispatcher> 
<docket>g</docket> 
<trailer_type>Extended oversize</trailer_type> 
<trailer_rego>p</trailer_rego> 
<hotshot>YES</hotshot> 
</item>
- <loaded>
<loaditem>123</loaditem> 
<loaditem>5452</loaditem> 
</loaded>
</dispatch>
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][COLOR=#000000] OutputFileName [/COLOR][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][COLOR=#000000] a [/COLOR][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]Integer[/COLOR][/SIZE]
[COLOR=#000000][SIZE=2]OutputFileName = "\My Documents\dispatch.xml"[/SIZE][/COLOR]
[SIZE=2][COLOR=#0000ff]Try[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][COLOR=#000000] XMLDoc [/COLOR][COLOR=#0000ff]As[/COLOR][COLOR=#0000ff]New[/COLOR][COLOR=#000000] XmlDocument[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][COLOR=#000000] RootElem [/COLOR][COLOR=#0000ff]As[/COLOR][COLOR=#000000] XmlElement[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][COLOR=#000000] SvcElem [/COLOR][COLOR=#0000ff]As[/COLOR][COLOR=#000000] XmlElement[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][COLOR=#000000] loadElem [/COLOR][COLOR=#0000ff]As[/COLOR][COLOR=#000000] XmlElement[/COLOR][/SIZE]
 
 
[COLOR=#000000][SIZE=2]XMLDoc.Load(OutputFileName)[/SIZE][/COLOR]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][COLOR=#000000] root [/COLOR][COLOR=#0000ff]As[/COLOR][COLOR=#000000] XmlNode = XMLDoc.DocumentElement[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][COLOR=#000000] estamp [/COLOR][COLOR=#0000ff]As[/COLOR][COLOR=#000000] XmlElement = XMLDoc.CreateElement("estamp")[/COLOR][/SIZE]
[COLOR=#000000][SIZE=2]estamp.InnerText = Format(Now, "dd-MM-yyyy").ToString[/SIZE][/COLOR]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][COLOR=#000000] dispatcher [/COLOR][COLOR=#0000ff]As[/COLOR][COLOR=#000000] XmlElement = XMLDoc.CreateElement("dispatcher")[/COLOR][/SIZE]
[COLOR=#000000][SIZE=2]dispatcher.InnerText = TextBox3.Text.ToString[/SIZE][/COLOR]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][COLOR=#000000] docket [/COLOR][COLOR=#0000ff]As[/COLOR][COLOR=#000000] XmlElement = XMLDoc.CreateElement("docket")[/COLOR][/SIZE]
[COLOR=#000000][SIZE=2]docket.InnerText = TextBox4.Text.ToString[/SIZE][/COLOR]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][COLOR=#000000] trailer_type [/COLOR][COLOR=#0000ff]As[/COLOR][COLOR=#000000] XmlElement = XMLDoc.CreateElement("trailer_type")[/COLOR][/SIZE]
[COLOR=#000000][SIZE=2]trailer_type.InnerText = ComboBox1.Text.ToString[/SIZE][/COLOR]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][COLOR=#000000] trailer_rego [/COLOR][COLOR=#0000ff]As[/COLOR][COLOR=#000000] XmlElement = XMLDoc.CreateElement("trailer_rego")[/COLOR][/SIZE]
[COLOR=#000000][SIZE=2]trailer_rego.InnerText = TextBox2.Text.ToString[/SIZE][/COLOR]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][COLOR=#000000] hotshot [/COLOR][COLOR=#0000ff]As[/COLOR][COLOR=#000000] XmlElement = XMLDoc.CreateElement("hotshot")[/COLOR][/SIZE]
[COLOR=#000000][SIZE=2]hotshot.InnerText = ComboBox3.Text.ToString[/SIZE][/COLOR]
 
[COLOR=#000000][SIZE=2]SvcElem = XMLDoc.CreateElement("item")[/SIZE][/COLOR]
[COLOR=#000000][SIZE=2]SvcElem.AppendChild(estamp)[/SIZE][/COLOR]
[COLOR=#000000][SIZE=2]SvcElem.AppendChild(dispatcher)[/SIZE][/COLOR]
[COLOR=#000000][SIZE=2]SvcElem.AppendChild(docket)[/SIZE][/COLOR]
[COLOR=#000000][SIZE=2]SvcElem.AppendChild(trailer_type)[/SIZE][/COLOR]
[COLOR=#000000][SIZE=2]SvcElem.AppendChild(trailer_rego)[/SIZE][/COLOR]
[COLOR=#000000][SIZE=2]SvcElem.AppendChild(hotshot)[/SIZE][/COLOR]
[COLOR=#000000][SIZE=2]loadElem = XMLDoc.CreateElement("loaded")[/SIZE][/COLOR]
[SIZE=2][COLOR=#0000ff]For[/COLOR][COLOR=#000000] a = 0 [/COLOR][COLOR=#0000ff]To[/COLOR][COLOR=#000000] ListBox1.Items.Count - 1[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][COLOR=#000000] loaditem [/COLOR][COLOR=#0000ff]As[/COLOR][COLOR=#000000] XmlElement = XMLDoc.CreateElement("loaditem")[/COLOR][/SIZE]
[COLOR=#000000][SIZE=2]loaditem.InnerText = ListBox1.Items(a)[/SIZE][/COLOR]
[COLOR=#000000][SIZE=2]loadElem.AppendChild(loaditem)[/SIZE][/COLOR]
[SIZE=2][COLOR=#0000ff]Next[/COLOR][COLOR=#000000] a[/COLOR][/SIZE]
[COLOR=#000000][SIZE=2]root.AppendChild(SvcElem)[/SIZE][/COLOR]
[COLOR=#000000][SIZE=2]root.AppendChild(loadElem)[/SIZE][/COLOR]
[COLOR=#000000][SIZE=2]XMLDoc.Save(OutputFileName)[/SIZE][/COLOR]
[COLOR=#000000][SIZE=2][COLOR=#0000ff]Catch[/COLOR] err [COLOR=#0000ff]As[/COLOR] Exception[/SIZE][/COLOR]
[COLOR=#000000][SIZE=2]Console.WriteLine("Err: " & err.Message)[/SIZE][/COLOR]
[SIZE=2][COLOR=#0000ff]End[/COLOR][COLOR=#0000ff]Try[/COLOR][/SIZE]

This is the format I would like the XML (see below) to be generated in if possible, I have been banging my head on the issue for a couple of days and have finally given up in frustration, and wonder if any one can help?




HTML:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> 
<dispatch>
<item>
<estamp>30-03-2006</estamp> 
<dispatcher>h</dispatcher> 
<docket>g</docket> 
<trailer_type>Extended oversize</trailer_type> 
<trailer_rego>p</trailer_rego> 
<hotshot>YES</hotshot> 
<loaded>
<loaditem>123</loaditem> 
<loaditem>5452</loaditem> 
</loaded>
</item>
</dispatch>
 
Last edited by a moderator:
Back
Top