• 使用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;
    }
  • 相关阅读:
    tesseract的简单使用
    快速添加请求头
    1010. 一元多项式求导 (25)
    1009. 说反话 (20)
    1008. 数组元素循环右移问题 (20)
    1007. 素数对猜想 (20)
    1006. 换个格式输出整数 (15)
    素数判断
    1002. 写出这个数 (20)
    1005. 继续(3n+1)猜想 (25)
  • 原文地址:https://www.cnblogs.com/melonlee/p/210882.html
Copyright © 2020-2023  润新知