Question

This is my XML,It is actually an InfoPath form with a word doc attachment in the Attachment node - but I have removed the code for better readablity.

<?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>

This is my attempt so far

 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.

I have also tried

 XmlNodeList nl = myDoc.SelectNodes("//my:scn1");

I need to get the raw source out of there so i can decode and save the word document. enter code here

Était-ce utile?

La solution

To get the namespace working, you need to use 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);

With this, nl will be populated.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top