问题描述
voidprint(XmlNodenode){switch(node.NodeType){caseXmlNodeType.Element:Console.WriteLine("<{0}>",node.Name.ToString());break;caseXmlNodeType.Text:Console.WriteLine("{0}",node.Value.ToString());break;}}voidtreeprint(XmlNodenode){print(node);if(node.HasChildNode){treeprint(node.FirstChild);print(node);}while(node.NextSibling!=null){node=node.NextSibling;treeprint(node);}}//------------------用上面的函数读取XML文档树的时候,为什么文档的节点超过3个,就出现问题呢?
解决方案
解决方案二:
if(node.HasChildNode){treeprint(node.FirstChild);print(node);//这句是不是多余了啊?}
解决方案三:
我着显示没问题的:----------------------------------------------------protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){XmlDocumentxmlDoc=newXmlDocument();xmlDoc.Load(Server.MapPath("classXml.xml"));XmlNodexn=xmlDoc.SelectSingleNode("school");treeprint(xn);}}voidprint(XmlNodenode){switch(node.NodeType){caseXmlNodeType.Element:Response.Write(node.Name.ToString()+"<br>");break;caseXmlNodeType.Text:Response.Write(node.Value.ToString()+"<br>");break;}}voidtreeprint(XmlNodenode){print(node);if(node.HasChildNodes){treeprint(node.FirstChild);print(node);}while(node.NextSibling!=null){node=node.NextSibling;treeprint(node);}}
解决方案四:
我的XML:-----------------------------------------<?xmlversion="1.0"encoding="utf-8"?><school><classname="classone"><studentid="1"><name>tom</name><sex>boy</sex></student><studentid="2"><name>jey</name><sex>boy</sex></student><studentid="3"><name>jam</name><sex>gril</sex></student><studentid="4"><name>christina</name><sex>gril</sex></student></class><classname="classtwo"><studentid="1"><name>jane</name><sex>gril</sex></student><studentid="2"><name>mark</name><sex>boy</sex></student><studentid="3"><name>sweety</name><sex>gril</sex></student></class><classname="classthree"><studentid="1"><name>sarah</name><sex>gril</sex></student><studentid="2"><name>jason</name><sex>boy</sex></student><studentid="3"><name>jett</name><sex>boy</sex></student></class></school>
解决方案五:
你这样写会简单点:------------------------------------------------usingSystem.Xml;usingSystem.Xml.XPath;.....protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){XmlDocumentxmlDoc=newXmlDocument();xmlDoc.Load(Server.MapPath("classXml.xml"));XmlNodexn=xmlDoc.SelectSingleNode("school");PrintNode(xn);}}publicvoidPrintNode(XmlNodexn){foreach(XmlNodexnCinxn.ChildNodes){if(xnC.NodeType==XmlNodeType.Element){Response.Write(xnC.Name+"<br>");}elseif(xnC.NodeType==XmlNodeType.Text){Response.Write(xnC.Value+"<br>");}PrintNode(xnC);}}
解决方案六:
怎么开两帖一样的!!??
解决方案七:
不知道啊,系统出问题了吧