read xml using c# help need

  • Jul 4, 2009
    7,259
    462
    83
    <item>
    <title>My Title</title>
    <link>mysite.com</link>
    <pubDate>Mon, 15 Oct 2012 04:39:41 GMT</pubDate>
    <description>this is my web site</description>
    <category>Computer</category>
    </item>

    xml file එකක format එක තියෙන්නෙ මෙන්න මේ විදියට. මට ඕන මේ xml එකේ title එක මම දෙන value එකකට සමාන වෙන සහ ඒ title එකට අදාලව xml file එකේ link , Description යටතේ තියෙන විස්තරේ ගන්න.මේක c# වලින් කරන්නෙ කොහොමද කියල කියල දෙනවද ?
     

    madbuddy

    Active member
  • Feb 6, 2010
    712
    169
    43
    muthu ate....
    1.You have to convert your xml to below format in order to get the node set relevant to a title.

    <item>
    <title name="My Title">
    <link>mysite.com</link>
    <pubDate>Mon, 15 Oct 2012 04:39:41 GMT</pubDate>
    <description>this is my web site</description>
    <category>Computer</category>
    </title>
    </item>


    2.I have used c#,XML and Xpath to check & retrieve values from the XML

    using System.Xml;

    //Creates a new XML documet
    XmlDocument _xml = new XmlDocument();

    //Loads the externam XMl doc to the code
    _xml.Load("xml_path");

    //Select all title element to a XMLNodeList
    XmlNodeList _list = _xml.SelectNodes("//item//title");

    //Looping each and check for the relevant node set
    foreach (XmlElement _ele in _list)
    {
    if (_ele.Attributes["name"].InnerText.Equals("My Title"))
    {
    string _link = _ele.SelectSingleNode("//link").InnerText;
    }
    }
     
  • Jul 4, 2009
    7,259
    462
    83
    machan mata oni mehema <title> </title> me tag 1 atule tiyenne unique value 1k. mata ona ea title 1 attribute a mama dena value 1ta samana nam eka atule <description> eka ganna.

    ea kiwwe mata search karanna ona title 1 kiyana value 1 description eka

    <item>
    <title>title1</>
    <description>Test</description>
    </item>

    <item>
    <title>Title2</item>
    <description>Test2</description>
    </item>

    menna mehema tiyena kota title 1 ekata adala description 1 ganna ona