XmlNode Value vs InnerText

后端 未结 5 2037
梦毁少年i
梦毁少年i 2020-12-08 18:03

I\'m creating a ping application for school with an XML full of URLs. I lost an hour because of XmlNode.Value was resulting in a null.

Then I changed i

5条回答
  •  不思量自难忘°
    2020-12-08 18:37

    I had a similar situation. What I did is, I picked the first child of the current node and checked if it is XMLtext, then displayed its value.

    XmlNodeList xNList = xDOC.SelectNodes("//" + XMLElementname);
    
    foreach (XmlNode xNode in xNList)
    {
        if (xNode.ChildNodes.Count == 1 && 
            xNode.FirstChild.GetType().ToString() == "System.Xml.XmlText")
        {
            XMLElements.Add(xNode.FirstChild.Value);
        }
        else
        {
            XMLElements.Add("This is not a Leaf node");
        }
    }
    

提交回复
热议问题