xml

Cosmo 2012-09-05 10:46:39
<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插入数据。。
...全文
147 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
chuzhaowei 2012-09-05
  • 打赏
  • 举报
回复
首先构建 entry 节点
xmlNode = mXMLOrderInfo.SelectSingleNode("ufinterface/accept/body");
xmlNode.ChildNodes.Add(entry 节点)
Cosmo 2012-09-05
  • 打赏
  • 举报
回复
加到100分都没人帮忙解决吗。。。。。
Cosmo 2012-09-05
  • 打赏
  • 举报
回复
就没人懂吗?求高手指教啊。。
xmlNode.SelectSingleNode(xmlNodeName)//只找第一个的节点,第二个节点怎样查询?
我用以上的方法来查找xml节点是否存在。如果我的body部分有两条entry,哪我应该怎样区分是第一个的还是第二个的。。
Cosmo 2012-09-05
  • 打赏
  • 举报
回复
xmlNode = mXMLOrderInfo.SelectSingleNode("//body//entry");
XmlNode xmlNodebody = mXMLOrderInfo.SelectSingleNode("//body");
XmlNode xmlNodeCopy = xmlNode.Clone();

for (int i = 0; i < j; i++)
{
if (i == 0)
{
CreateXmlNode(xmlNode, dt, ds, i);
}
else
{
//XmlNode xmlNodeNew = xmlNodeCopy.Clone();

CreateXmlNode(xmlNodeCopy, dt, ds, i);
xmlNodebody.AppendChild(xmlNodeCopy);

}
}


//创建节点
public static void CreateXmlNode(XmlNode xmlNode, DataTable dt, DataTable mHeadTable, int j)
{
string TabFieldName;
DataRow[] rows = null;
rows = dt.Select();
// xmlNode.ParentNode;
foreach (var item in rows)
{
string xmlNodeName = item["XmlField"].ToString();
TabFieldName = item["TableField"].ToString();
// XmlNode q = xmlNode.ParentNode;
XmlNode tempXmlNode = null;
if (j < 1)
{
tempXmlNode = xmlNode.SelectSingleNode("//body//entry//" + xmlNodeName);
} if (j >= 1)
{
tempXmlNode = xmlNode.SelectSingleNode("//entry//" + xmlNodeName);
}

if (tempXmlNode != null)
{
tempXmlNode.InnerText = mHeadTable.Rows[j][TabFieldName].ToString();
}

}
}
这样写的代码不行,如果子表有多条记录只能插入第一条。。求高手指教。。
csdnfan 2012-09-05
  • 打赏
  • 举报
回复

XmlNodeList nodeList;
XmlNode root = doc.DocumentElement;
nodeList=root.SelectNodes(xmlNodeName);
niaoked 2012-09-05
  • 打赏
  • 举报
回复
XmlNodeList nodes=xmlDoc.SelectNodes(xpath表达式);
要取任意一个都可以。
sj490790083 2012-09-05
  • 打赏
  • 举报
回复
xmlDoc.SelectNodes(xpath表达式)

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧