Results 1 to 3 of 3

Thread: xml help[RESOLVED]

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    xml help[RESOLVED]

    been trying and going insane

    I have written an xml doc like he following:

    <Main>
    <Something1>valueHere</Something1>
    <Something2>valueHere</Something2>
    </Main>


    but how do I read the first element (Something1) and then the text inbetween? (valueHere)

    this is what I have:

    Code:
    XmlTextReader tr = new XmlTextReader(path);
    while(tr.Read())
    {
       if (tr.NodeType == XmlNodeType.Text)
       {
          tr.ReadString();
          if (tr.Name.Equals("Something1"))
          {
              //value/name
          }
    ..
    ..
       }
    }
    but it only gets the Name (Somethingx) but not the inner value.

    any ideas?
    Last edited by Techno; Sep 4th, 2005 at 10:37 AM.

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: xml help[RESOLVED]

    post your solution if you don't mind, in case someone else is looking for the same thing
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: xml help[RESOLVED]

    sure

    Code:
    XmlTextReader reader = new XmlTextReader(@pathToXmlFile);
    
    while (reader.Read())
    {
    	reader.MoveToContent();
    	if (reader.NodeType == XmlNodeType.Element)
    	{
    		if (reader.Name.Equals("TagNameToLookFor"))
    		{
    			reader.ReadStartElement(reader.LocalName);
    			string theValueOfThisTag = reader.Value;
    		}
                              //..
                              //..
                 }
    }

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