XMLNodeList not populating
本文关键字:populating not XMLNodeList | 更新日期: 2023-09-27 18:20:55
这是我的XML,它实际上是一个InfoPath表单,在"附件"节点中有一个word文档附件,但为了更好的可读性,我删除了代码。
<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.527" productVersion="14.0.0" PIVersion="1.0.0.0" href="http://intranet/workspace/departments/IT/fakehomepage/Testing/Forms/template.xsn" name="urn:schemas-microsoft-com:office:infopath:Testing:-myXSD-2011-11-22T09-08-23" ?><?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.3"?><?mso-infoPath-file-attachment-present?><my:Template xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapEnc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:tns="http://www.sourcecode.co.za/webservices/RuntimeServices" xmlns:d="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields" xmlns:pc="http://schemas.microsoft.com/office/infopath/2007/PartnerControls" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:ma="http://schemas.microsoft.com/office/2009/metadata/properties/metaAttributes" xmlns:ns1="http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields" xmlns:q="http://schemas.microsoft.com/office/infopath/2009/WSSList/queryFields" xmlns:dms="http://schemas.microsoft.com/office/2009/documentManagement/types" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-11-22T09:08:23" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-za">
<my:scn1>
<my:Attachment>the raw source-removed for space saving</my:Attachment>
<my:DataValue>Hello-2013-07-04T09:05:50</my:DataValue>
</my:scn1>
<my:scn2></my:scn2>
<my:scn3></my:scn3>
<my:scn4></my:scn4>
<my:scnSubmit></my:scnSubmit>
<my:scnHideMe></my:scnHideMe>
</my:Template>
这是我迄今为止的尝试
XmlDocument myDoc = new XmlDocument(); //works
myDoc.Load(@"Form.xml"); //works
XmlNodeList nl = myDoc.SelectNodes("//Attachment"); //Doesn't work, nodecount still zero.
foreach (XmlNode n in nl)//skips because no nodes loaded.
我也试过
XmlNodeList nl = myDoc.SelectNodes("//my:scn1");
我需要从那里得到原始来源,这样我就可以解码并保存word文档。在此处输入代码
要使命名空间工作,需要使用XmlNamespaceManager
。
XmlDocument myDoc = new XmlDocument();
myDoc.Load(@"Form.xml");
XmlNamespaceManager xmlNsMgr = new XmlNamespaceManager(myDoc.NameTable);
xmlNsMgr.AddNamespace("my", myDoc.DocumentElement.NamespaceURI);
XmlNodeList nl = myDoc.SelectNodes("//my:Attachment", xmlNsMgr);
这样,将填充nl
。