zoukankan      html  css  js  c++  java
  • 使用infopath中的xpath来读取sps中的数据

    在infopath中读取xml数据的时候用selectSingleNode("/信息_/@价格");死活弄不出来,去掉@就没问题了,结果在读sps中的数据的时候就必须用@,xpath的语法也要求用@,但是为什么读xml就不行,真是郁闷

    var selected=XDocument.DOM.selectSingleNode("//my:编号").text;

        objXml 
    = XDocument.GetDOM("(基本信息)");
        
        
    var price = objXml.selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:基本信息_[@编号='"+selected+"']");
       
        
        
    if(price!=null)
        {
            
    if(price.selectSingleNode('@价格')!=null)
            {
            setNodeValue(
    "//my:价格",price.selectSingleNode('@价格').text);
            }
    else
            {
            setNodeValue(
    "//my:价格",'');
            }
    }

      

    读取数据的时候还是抱错,原来少了提取sps数据的命名空间
        XDocument.GetDOM("(基本信息)").setProperty("SelectionNamespaces",'xmlns:q="http://schemas.microsoft.com/office/infopath/2003/ado/queryFields" xmlns:d="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"');

    同时将提取的数据表示在infopath的文本框中需要:
    function setNodeValue(xpath, value)
    {
        
    var xmlNode = getNode(xpath);

        
    if (!xmlNode)
            
    return;

        
    // The xsi:nil needs to be removed before we set the value.
        if (value != "" && xmlNode.getAttribute("xsi:nil"))
            xmlNode.removeAttribute(
    "xsi:nil");

        
    // Setting the value would mark the document as dirty.
        // Let's do that if the value has really changed.
        if (xmlNode.text != value)
            xmlNode.text 
    = value;
    }
    function getNode(xpath)
    {
        
    // Both XML node and absolute XPath are allowed.
        if (typeof(xpath) == "string")
            
    return XDocument.DOM.selectSingleNode(xpath);
        
    else
            
    return xpath;
    }
  • 相关阅读:
    Centos 7.X 安装JDK1.8
    CentOS 7.X 搭建时间服务器 --- chrony
    CentOS 7.X 设置系统时间
    CentOS 7.X 关闭SELinux
    C11工具类:时间处理
    C11内存管理之道:智能指针
    C11性能之道:标准库优化
    C11性能之道:转移和转发
    C11性能之道:右值引用
    C11简洁之道:tupe元祖
  • 原文地址:https://www.cnblogs.com/melonlee/p/210882.html
Copyright © 2011-2022 走看看