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;
    }
  • 相关阅读:
    HDU.2899.Strange fuction(牛顿迭代)
    BZOJ.3771.Triple(母函数 FFT 容斥)
    树的实现(2)
    树的练习
    死锁问题
    进程的三种状态
    线程的同步与实现
    进程间通信详解
    进程和线程以及它们的区别
    https协议
  • 原文地址:https://www.cnblogs.com/melonlee/p/210882.html
Copyright © 2011-2022 走看看