dimanche 29 juillet 2018

Null value while trying to read XML data

I tried to read XML data that matches my post id string (not null) attributes, but it returns null even though I have tried several times.

protected void Update_btn_click(object sender, EventArgs e)
        {
            String new_title = newtitle.Text.ToString();
            String new_description = update_des.Value.ToString();
            String postid = Request.QueryString["pid"];

            System.Diagnostics.Debug.WriteLine(postid); 


            string filename = "C:\\Users\\user\\Source\\Repos\\FoodBlog\\FoodBlog\\Data\\blog_post.xml";
                        XmlDocument xml_doc = new XmlDocument();
            xml_doc.Load(filename);

            XmlTextReader xtr = new XmlTextReader(filename);



            XmlNodeList elemList = xml_doc.GetElementsByTagName("post");
            for (int i=0;i<elemList.Count; i ++)
            {
                string getValue = elemList[i].Attributes[postid].ChildNodes[1].InnerText;
                System.Diagnostics.Debug.WriteLine(getValue);
            }

XML data :

<Posts)
<post pid="pid2623">
    <title>Test</title>
    <description>Test</description>
    <subtitle>Test</subtitle>
    <date>7/29/2018 12:00:00 AM</date>
    <author>est</author>
  </post>
</Posts>




Aucun commentaire:

Enregistrer un commentaire