I posted once under Getting Started and only getting one response after 5 days, I realized I should have posted the issue here. I am actually experiencing two issues, well one issue and one total lack of knowledge... well two lacks of knowledge.
My experience writting xml to this point has been extremely minimal, thus the getting started post. So here goes, hope I explain it well enough to make sence?
I need to product an xml document that fits this format:
The first part (ordercust) is customer info that is provided through a web form. The second part of the xml document is the product or item information which I need to pul from a data set.... for each xml document, there will be only 1 ordercust entry and
as many orderitems as products put into there cart. It has to follow this format because it gets sucked into another system that I have no control over.
The second part of my issues is getting my output formated. Here is some of my code that does not do the job:
' sets outputted file name and path
Dim strXFile As String = "~/App_Data/xmlOrders/" + CustNumber + "-" + OrderID + "-" + sDate.ToString(Format) + ".xml"
'file setting for format
Dim settings As New XmlWriterSettings()
settings.Indent = True
settings.NewLineOnAttributes = True
' Create a new XmlTextWriter instance
Dim writer As New XmlTextWriter(Server.MapPath(strXFile), Encoding.UTF8)
And here is also another issue... I would have thought to put the settings after the encodeing.utf8 but here I get an error that there are to many attributes:
writer.WriteStartDocument()
writer.WriteStartElement("order")
writer.WriteStartElement("ordercust")
writer.WriteElementString("ordernum", intOrder)
writer.WriteElementString("customername", strName)
writer.WriteElementString("customeraddr", straddr)
writer.WriteElementString("customercity", strCity)
writer.WriteEndElement()
' Somehow this is where I need to have my dataset??? just how?
writer.WriteStartElement("orderproducts")
writer.WriteStartElement("orderitem")
writer.WriteElementString("itemnumber", intItem)
writer.WriteElementString("itemname", strItem)
writer.WriteElementString("orderqty", intQty)
writer.WriteElementString("itemprice", dblPrice)
'close dataset??
writer.WriteEndElement()
writer.WriteEndElement()
'ending and closing the xml doc
writer.WriteEndElement()
writer.WriteEndElement()
writer.WriteEndDocument()
writer.Close()
The abover is a very simplied structure but if I could get a working sample I can figure the rest of it out? Am I going about this all wrong?
Member
542 Points
278 Posts
xmwriter and dataset plus formating issues
May 13, 2014 02:29 PM|bobmmp|LINK
I posted once under Getting Started and only getting one response after 5 days, I realized I should have posted the issue here. I am actually experiencing two issues, well one issue and one total lack of knowledge... well two lacks of knowledge.
My experience writting xml to this point has been extremely minimal, thus the getting started post. So here goes, hope I explain it well enough to make sence?
I need to product an xml document that fits this format:
The first part (ordercust) is customer info that is provided through a web form. The second part of the xml document is the product or item information which I need to pul from a data set.... for each xml document, there will be only 1 ordercust entry and as many orderitems as products put into there cart. It has to follow this format because it gets sucked into another system that I have no control over.
The second part of my issues is getting my output formated. Here is some of my code that does not do the job:
And here is also another issue... I would have thought to put the settings after the encodeing.utf8 but here I get an error that there are to many attributes:
The abover is a very simplied structure but if I could get a working sample I can figure the rest of it out? Am I going about this all wrong?
Any and all help is appreciated.... thanks.
aDigitalHost.com
All-Star
16806 Points
2777 Posts
Re: xmwriter and dataset plus formating issues
May 14, 2014 02:33 AM|Kevin Shen - MSFT|LINK
Hi bobmmp,
For your problem,I suggest you can try to use Linq to xml to create new element and add to xml.
About your post ,I write a sample for you in c#.Here is my code:
First xml file:
Here is sercer code:
About how to use LINQ to XML ,please refer to link below:
http://msdn.microsoft.com/en-us/library/bb387061.aspx
Hope it can help you.
Best Regards,
Kevin Shen.
Member
542 Points
278 Posts
Re: xmwriter and dataset plus formating issues
May 14, 2014 11:44 AM|bobmmp|LINK
I would if I could.... this is a legacy project on asp.net 2.0
aDigitalHost.com
All-Star
16806 Points
2777 Posts
Re: xmwriter and dataset plus formating issues
May 15, 2014 12:23 AM|Kevin Shen - MSFT|LINK
Hi bobmmp,
you can use XmlDocument to select specify node,and add XElement to the node ,just like below:
Hope it can help you.
Best Regards,
Kevin Shen.