2013-07-04 2 views
0

Ceci est mon XML, Il s'agit en fait d'un formulaire InfoPath avec une pièce jointe Word dans le nœud Attachment - mais j'ai supprimé le code pour une meilleure lisibilité.XMLNodeList non rempli

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

C'est ma tentative jusqu'à

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. 

J'ai aussi essayé

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

Je dois obtenir la source première de là pour que je puisse décoder et enregistrer le document Word . entrez le code ici

Répondre

1

Pour que l'espace de noms fonctionne, vous devez utiliser 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); 

Avec ceci, nl sera rempli.

+0

Merci Mate, fonctionne parfaitement! – Batista

Questions connexes