Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating an XML Document

Status
Not open for further replies.

nicklieb

Programmer
Oct 17, 2002
383
GB
I have been looking around for examples, but have yet to find anything that I feel fits my 'problem'

it's not really a problem, but I'm trying to find an easier way of populating this XML file.

it is quite large and is being used to interact with a courier system.

I have already built a working version in classic asp about a year ago, that basically treats the XML document as a large string and replace various node values.

I am updating to it, as i need to create it as a web service for some web apps I am developing in .net 2.0 in vis studio 2005

Pre amble over, lets get into it.

I have been trying to use an XSD to give me a object that i could populate and then apply to the XML document.

I know that i can set all the text I want by using the XmlElement and then pickout the relevant XmlNode and then populate it as follows

Code:
XmlElement root = myxml.DocumentElement;
XmlNode request = root.SelectSingleNode("/Request");
request.ChildNodes.Item(0).InnerText = "this is test";
request.ChildNodes.Item(1).InnerText = _username;
request.ChildNodes.Item(1).InnerText = _password;

but to fully populate it i would need around 150 lines of code of the childNode type statements and am not that happy at Hard Coding the various positions of the specific nodes.

So my question as stated above is can I extract an object by creating an XSD and populate that object and then apply it to the XML.

May thanks in advance
 
why don't you make your objects write themselves?

myObject.SaveToXml(myxmltextwriter);

and have your object write directly to that XmlTextWriter?

I then use another method ReadFromXml(somexmlNode);

to parse its own data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top