全局变量m_xDoc
我有
的财产public XmlDocument xDoc
{
get {return m_xDoc; }
set {value = m_xDoc; }
}
string xml = "<head><body><Inner> welcome </head></Inner><Outer> Bye</Outer></body></head>"
现在我必须使用此字符串将该属性设置为XML文档...请指导我如何执行此操作
答案 0 :(得分:62)
使用XmlDocument的LoadXml方法;
string xml = "<head><body><Inner> welcome </head> </Inner> <Outer> Bye</Outer></body></head>";
xDoc.LoadXml(xml);
答案 1 :(得分:21)
// using System.Xml;
String rawXml =
@"<root>
<person firstname=""Riley"" lastname=""Scott"" />
<person firstname=""Thomas"" lastname=""Scott"" />
</root>";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(rawXml);
我认为这应该有用。
答案 2 :(得分:13)
string test = "<body><head>test header</head></body>";
XmlDocument xmltest = new XmlDocument();
xmltest.LoadXml(test);
XmlNodeList elemlist = xmltest.GetElementsByTagName("head");
string result = elemlist[0].InnerXml;
//result -> "test header"
答案 3 :(得分:4)
xDoc.LoadXML("<head><body><Inner> welcome </head> </Inner> <Outer> Bye</Outer>
</body></head>");