|
-
Jan 15th, 2006, 10:19 PM
#1
Thread Starter
Junior Member
Read String into XMLTextReader
Hi,
I have the following string in XML format:
<CustomerDetails>
<CompanyName>ONLINE TEST</CompanyName>
<CustomerName>CAROL DAVIS</CustomerName>
<OrderNumber>H897</OrderNumber>
<OrderNumber>H435</OrderNumber>
</CustomerDetails>
I want to be able to read this in as XML so I can easily work with the nodes and their values.
How do I do this?
Thank You
R
-
Jan 16th, 2006, 12:19 AM
#2
Sleep mode
Re: Read String into XMLTextReader
Ummm , I'm sorry I can't give you a sample code but if you can check XMLDocument class , I think you'd probably figure something out.
-
Jan 16th, 2006, 10:34 AM
#3
Hyperactive Member
Re: Read String into XMLTextReader
OK, If i understand your question, you have the xml in a string and want to read it as xml ok. Here's how I do it:
using System.Xml; // Namespace to use XML.
...
string StrXml = // Your xml string assigned here.
// Create a new XmlDocument object.
XmlDocument ReadDoc = new XmlDocument();
// Input the xml string to be read as XML.
ReadDoc.LoadXml(StrXml);
// Nodereader object for the document.
XmlNodeReader reader = new XmlNodeReader(ReadDoc);
// loop through the reader and get informatin from the xml file
while(reader.Read())
{
if(reader.NodeType == XmlNodeType.XmlDeclaration)
{
// Display xml name and value.
txtXmlDec.Text = reader.Name+ " " +reader.Value;
}/* end if */
etc. (look in the msdn for xmlnodereader and you'll see the different types of nodetypes you could use to read from.)
}/* end while */
... this works for me - Jennifer
-
Jan 16th, 2006, 01:51 PM
#4
Thread Starter
Junior Member
Re: Read String into XMLTextReader - RESOLVED
That worked great thanks for your help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|