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:价格",'');
}
}
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;
}
{
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;
}