//string result = GetPageHtml(_payUrl, "", "gb2312");
result ="<?xml version=\"1.0\" encoding=\"gb2312\"?>\r\n<Root>\r\n<Result>1</Result>\r\n<Msg></Msg>\r\n</Root>\r\n"
XmlDocument dom = new XmlDocument();
dom.Load(result.Replace("\r\n",""));
XmlNode node = dom.DocumentElement;
XmlNode t1Node = node.SelectSingleNode("Result");
XmlNode t2Node = node.SelectSingleNode("Msg");
string rest = t1Node.InnerText;
code execution to : dom.Load (result.Replace ("\ r \ n", "")); on the problem :
as shown below:
solving , first thanked !
------ Solution ---------------------------------------- ----
dom.Load () method parameter should be the path to the file , right xml
\ r \ n
Obviously not the path , nor is it after replacement
------ Solution -------------------------- ------------------
dom.Load ( path ) that is clearly not the path you are finished parsing an xml text
--- --- Solution --------------------------------------------
Use XmlReader
------ Solution ------------------------------------- -------
example xml file in my project an xml file
XmlDocument xml = new XmlDocument ();
xml.Load (Server.MapPath (".. / xml / xl.xml"); Load is to read the file path.
You just is the content written into the
------ Solution ---------------------------- ----------------
method using XmlDocument.LoadXml
using System;
using System.Xml;
public class Sample {
public static void Main() {
// Create the XmlDocument.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<item><name>wrench</name></item>");
// Add a price element.
XmlElement newElem = doc.CreateElement("price");
newElem.InnerText = "10.95";
doc.DocumentElement.AppendChild(newElem);
// Save the document to a file and auto-indent the output.
XmlTextWriter writer = new XmlTextWriter("data.xml",null);
writer.Formatting = Formatting.Indented;
doc.Save(writer);
}
}
Reference:
http://msdn. microsoft.com / zh-cn / library / system.xml.xmldocument.loadxml (v = vs.80). aspx
------ Solution ---------- ----------------------------------
doc.LoadXml ()
----- - For reference only ---------------------------------------
seeking ways !
------ For reference only -------------------------------------- -
---- - For reference only ---------------------------------------
doc.LoadXml ()
没有评论:
发表评论