XML Reader question

Discussion in 'Software' started by eksilva, Aug 20, 2009.

  1. eksilva

    eksilva

    Joined:
    Aug 20, 2009
    Messages:
    2
    I don't have a lot of experience with xml files. I am trying to read the string "English Version" from the XML below in C# given:
    "BUTTON_TEXT" and ""en"

    Does anyone know how to write a method passing the 2 variables above to get the result = "English Version" ?


    <?xml version="1.0" encoding="UTF-16"?>
    <localization>
    <metadata>
    <version number="1.0">
    <date>2009-07-26</date>
    <comment/>
    </version>
    <languages>
    <language lcid="1033" code="en">US English</language>
    <language lcid="1034" code="de">German</language>
    </languages>
    </metadata>
    <descriptions>
    <string key="{NLS_KEY}">
    <locale code="en">NLS value</locale>
    <locale code="de">NLS wert</locale>
    </string>
    <string key="BUTTON_TEXT">
    <locale code="en">English Version</locale>
    <locale code="de">German Version</locale>
    </string>
    </descriptions>
    </localization>
     
    eksilva, Aug 20, 2009
    #1
    1. Advertising

  2. eksilva

    saurabhm

    Joined:
    Aug 20, 2009
    Messages:
    4
    Hi eksilva,

    Below is the code of function as u desired.
    you can call it with passing to arguments ("BUTTON_TEXT","en")

    Using System.Xml;

    private string GetVersion(string key, string local)
    {
    XmlDocument xdoc = new XmlDocument();
    xdoc.Load(Server.MapPath("~/App_Data/Test.xml"));
    XmlNodeList _nodes = xdoc.GetElementsByTagName("string");
    foreach (XmlNode _node in _nodes)
    {
    foreach (XmlAttribute atrString in _node.Attributes)
    {
    if (atrString.Value == key)
    {
    foreach (XmlNode _localNode in _node.ChildNodes)
    {
    foreach (XmlAttribute atrLocal in _localNode.Attributes)
    {
    if (atrLocal.Value == local)
    {
    return _localNode.InnerText;
    }
    }
    }
    }
    }
    }
    return "No version found in Document based on parameters.";
    }

    "Good is enemy of Great."
     
    saurabhm, Aug 21, 2009
    #2
    1. Advertising

  3. eksilva

    eksilva

    Joined:
    Aug 20, 2009
    Messages:
    2
    Thank you so much!

    That was exacly what I needed!
     
    eksilva, Aug 24, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Reg M

    Do I need an XML reader?

    Reg M, Oct 12, 2006, in forum: Firefox
    Replies:
    1
    Views:
    395
    Leonidas Jones
    Oct 12, 2006
  2. aaronep@pacbell.net

    card reader for 1 gig type m xd card reader?

    aaronep@pacbell.net, Dec 12, 2005, in forum: Digital Photography
    Replies:
    5
    Views:
    851
    Colin D
    Dec 16, 2005
  3. Mike
    Replies:
    7
    Views:
    865
  4. akiwi
    Replies:
    1
    Views:
    767
    Gordon
    Mar 28, 2005
  5. Yeah Right

    Samsung DVD reader/CD Reader/writer SM-352

    Yeah Right, Feb 7, 2008, in forum: NZ Computing
    Replies:
    35
    Views:
    2,401
    bambam
    Feb 13, 2008
Loading...

Share This Page