日期:2014-05-17  浏览次数:20794 次

xml
<ufinterface roottag="accept" billtype="" docid="" receiver="" sender="" proc="" codeexchanged="" exportneedexch="" version="2.0">
<accept>
<header> <vouchtype /> 
  <vouchcode /> 
  <vouchdate /> 
  <period /> 
  <customercode /> 
  <departmentcode /> 
  <sitemcode /> 
  <citemname /> 
  <oppositebankname /> 
  <bankname /> 
  <bankaccount /> 
  <define1 /> 
  <define2 /> 
  <define3 /> 
  <define4 /> 
  <define5 /> 
  <define6 /> 
  <define7 /> 
  <define8 /> 
  <define9 /> 
  <define10 /> 
  <dealmode /> 
</header>

 <body><entry> <mainid /> 
  <type /> 
  <customercode /> 
  <originalamount /> 
  <amount /> 
  <itemcode /> 
  <projectclass /> 
  <project /> 
  <departmentcode /> 
  <personcode /> 
  <orderid /> 
  <itemname /> 
  <ccontype /> 
  <cconid /> 
  <iamt_s /> 
  <iramt_s /> 
</entry>  
</body> </accept>
  </ufinterface>

head为主表,body 为子表(可能有多条数据),我的xml模板如上,怎样动态往body插入数据。。

------解决方案--------------------
首先构建 entry 节点
xmlNode = mXMLOrderInfo.SelectSingleNode("ufinterface/accept/body");
xmlNode.ChildNodes.Add(entry 节点)
------解决方案--------------------
xmlDoc.SelectNodes(xpath表达式)
------解决方案--------------------
XmlNodeList nodes=xmlDoc.SelectNodes(xpath表达式);
要取任意一个都可以。
------解决方案--------------------
C# code

XmlNodeList nodeList;
XmlNode root = doc.DocumentElement;
nodeList=root.SelectNodes(xmlNodeName);