欢迎光临
我们一直在努力

程序员XmlDocument.SelectNodes不返回InfoPath XML的节点 – c#

程序员面试经验

我正在尝试查询InfoPath XML文档的附件,但查询无法返回任何节点。我没有使用XmlDocument类的丰富经验。我相信我的问题与命名空间有关。有没有人对此有任何见识。

// Get the binary stream of the file Stream formStream = file.OpenBinaryStream(); // Load the stream into an XPathDocument object XmlDocument ipForm = new XmlDocument(); ipForm.Load(formStream);  //Create a NameSpaceManager object and add the namespace of the form to it XmlNamespaceManager ns = new XmlNamespaceManager(ipForm.NameTable); ns.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2015-07-13T20:54:32"); //http://schemas.microsoft.com/office/infopath/2003/myXSD/2015-07-13T20:54:32 | http://www.w3.org/XML/1998/namespace    //Get the XML node containing the file attachment   //XmlNode attachmentNode = ipForm.SelectSingleNode("/my:myFields/my:Attachments", ns);   //No nodes returned here   XmlNodeList myNodeList = ipForm.SelectNodes("/my:myFields/my:Attachments", ns);  

XML格式

<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.830" productVersion="14.0.0" PIVersion="1.0.0.0" href="http://sharepoint.calpine.com/sites/dept/fleetsupport/issues/Issues/Forms/template.xsn" name="urn:schemas-microsoft-com:office:infopath:Issues:-myXSD-2015-03-30T21-16-50" ?><?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.3"?><?mso-infoPath-file-attachment-present?><my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pc="http://schemas.microsoft.com/office/infopath/2007/PartnerControls" xmlns:ma="http://schemas.microsoft.com/office/2009/metadata/properties/metaAttributes" xmlns:d="http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields" xmlns:q="http://schemas.microsoft.com/office/infopath/2009/WSSList/queryFields" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:dms="http://schemas.microsoft.com/office/2009/documentManagement/types" xmlns:tns="http://schemas.microsoft.com/sharepoint/soap/" xmlns:s1="http://microsoft.com/wsdl/types/" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:ns1="http://microsoft.com/webservices/SharePointPortalServer/UserProfileService" xmlns:ns2="http://schemas.microsoft.com/sharepoint/soap/directory/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:ns3="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2015-03-30T21:16:50" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-us"> <my:InstrumentTag>222</my:InstrumentTag> <my:IssueDate>2015-07-25</my:IssueDate>  <my:listName>{B6CDAA90-0F94-4127-A50F-D599952B23CD}</my:listName> <my:strFormName>TestFormName</my:strFormName>    <my:Attachments>     <my:Attachment>/*AttachmentBinary*/</my:Attachment> </my:Attachments> <my:Attachments>     <my:Attachment>/*AttachmentBinary*/</my:Attachment> </my:Attachments> 

参考方案

试试这个

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using System.Xml.Linq;  namespace ConsoleApplication37 {     class Program     {         const string FILENAME = @"temptest.xml";         static void Main(string[] args)         {              XDocument doc = XDocument.Load(FILENAME);              var results = doc.Descendants().Where(x => x.Name.LocalName == "myFields").Select(y => new             {                 instrumentTag = y.Elements().Where(z => z.Name.LocalName == "InstrumentTag").FirstOrDefault().Value,                 issueDate = y.Elements().Where(z => z.Name.LocalName == "IssueDate").FirstOrDefault().Value,                 listName = y.Elements().Where(z => z.Name.LocalName == "listName").FirstOrDefault().Value,                 strFormName = y.Elements().Where(z => z.Name.LocalName == "strFormName").FirstOrDefault().Value,                 Attachments = y.Elements().Where(z => z.Name.LocalName == "Attachments").Select(a => new {                    attachment = a.Elements().Where(b => b.Name.LocalName == "Attachment").Select(c => c.Value).FirstOrDefault()                 }).ToList(),             }).ToList();         }     } } 

Div单击与单选按钮相同吗? – php

有没有一种方法可以使div上的click事件与表单环境中的单选按钮相同?我只希望下面的div提交值,单选按钮很丑代码输出如下:<input id="radio-2011-06-08" value="2011-06-08" type="radio" name="radio_date&#…

将python scikit学习模型导出到pmml – python

我想将python scikit-learn模型导出到PMML。哪个python软件包最合适?我阅读了有关Augustus的内容,但是我无法使用scikit-learn模型找到任何示例。 python大神给出的解决方案 SkLearn2PMML是 JPMML-SkLearn命令行应用程序周围的薄包装。有关受支持的Scikit-Learn Estimator和…

故障排除“警告:session_start():无法发送会话高速缓存限制器-标头已发送” – php

我收到警告:session_start()[function.session-start]:无法发送会话缓存限制器-标头已发送(错误输出开始如果我将表单数据提交到其他文件进行处理,则可以正常工作。但是,如果我将表单数据提交到同一页面,则会出现此错误。请建议<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0…

SOAPFaultException部署在Tomcat上时,但在GlassFish中工作正常 – java

朋友们,我一直在尝试很多,阅读了很多论坛,但无法理解为什么出现此问题。我使用契约优先方法创建了一个Jax-WS WebService。创建WSDL和XSD,然后使用wsimport工具生成其余工件,为SEI提供实现。将WebService应用程序部署到Eclipse Helios中的GlassFish(Glassfish适配器和Eclipse中安装的插件)。…

Telerik单选按钮所需的字段验证器 – javascript

如何设置Telerik单选按钮所需的字段验证器?我想在按钮单击“ BtnSave”上设置必填字段验证器吗?请帮忙!<telerik:RadButton ID="radio_male" runat="server" ToggleType="Radio" AutoPostBack="fa…

赞(0)
未经允许不得转载: 京大飞辅助网程序员面试-区块链javago面经 » 程序员XmlDocument.SelectNodes不返回InfoPath XML的节点 – c#

相关推荐

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址