Results 1 to 4 of 4

Thread: Read String into XMLTextReader

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Location
    Christchurch, NZ
    Posts
    18

    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

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    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.

  3. #3
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    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

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Location
    Christchurch, NZ
    Posts
    18

    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
  •  



Click Here to Expand Forum to Full Width