代码这样写的
[C#] 纯文本查看 复制代码 string xmlStr = "<Response> <QryReportListResult> <s:schema id=\"DefaultDataSet\" xmlns=\"\" attributeFormDefault=\"qualified\" elementFormDefault=\"qualified\" xmlns:s=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\"> <s:element name=\"DefaultDataSet\" msdata:IsDataSet=\"true\"> <s:complexType> <s:choice maxOccurs=\"unbounded\"> <s:element name=\"QryReportList\"> <s:complexType> <s:sequence> <s:element name=\"VisitNumberDR\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"Status\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"StatusDesc\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"EpisodeNo\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"Labno\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"RegNo\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"RecordNo\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"PatName\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"SurName\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"PatSex\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"PatAge\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"Location\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"Urgent\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"TestSetDesc\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"SpecimenDesc\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"AdmType\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"ReportDR\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"ResultFlag\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"CollectDate\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"CollectTime\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"ReceiveDate\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"ReceiveTime\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"AcceptDate\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"AcceptTime\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"AuthDate\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"AuthTime\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"ColStyler\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"InfectFlag\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"InfectAlert\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"WorkGroupMachineDR\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"WorkGroupMachine\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"Printed\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"PrinteFlag\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"CollectUser\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"ReceiveUser\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"AcceptUser\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"AuthUser\" type=\"s:string\" minOccurs=\"0\">1</s:element> <s:element name=\"SelfPrintFlag\" type=\"s:string\" minOccurs=\"0\">1</s:element> </s:sequence> </s:complexType> </s:element> </s:choice> </s:complexType> </s:element> </s:schema> </QryReportListResult> <RetVal>0</RetVal> <Error/> <Node>QryReportList</Node> <RowCount>0</RowCount> <ResType>0</ResType> </Response>".Trim();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlStr);
//XmlNodeList value = xmlDoc.SelectNodes("/Response/QryReportListResult/s:schema/s:element/s:complexType/s:choice/s:element/s:complexType/s:sequence");
XmlElement root = xmlDoc.DocumentElement;
string nameSpace = root.NamespaceURI;
XmlNamespaceManager xmlNameSpace = new XmlNamespaceManager(xmlDoc.NameTable);
xmlNameSpace.AddNamespace("s", nameSpace);
XmlNodeList x = xmlDoc.GetElementsByTagName("QryReportList", "");
XmlNodeList value2 = xmlDoc.SelectNodes("/s:schema/s:element/s:complexType/s:choice/s:element/s:complexType/s:sequence/s:element", xmlNameSpace);
int i = xmlDoc.SelectNodes("/Response/QryReportListResult/s:schema/s:element/s:complexType/s:choice/s:element/s:complexType/s:sequence/s:element", xmlNameSpace).Count; |