Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在不附加子节点值的情况下获取 xml 节点的值?Innertext 给出了附加子项的值。有什么方法可以从父节点的值中删除该字符串?/text() 不起作用,因为我正在反序列化 xml 文件。
使用 LINQ to XML:
string xml = "<rootNode><node1><node11>v1</node11></node1></rootNode>"; XDocument xDocument = XDocument.Parse(xml); XElement xmlElement = xDocument.Element("node11"); string value = xmlElement.Value; // v1