
利用aelement("b")asXML()即可获得到 <b>123</b>字符串Str
又可以用
DocumentHelperparseText(str);
转化为XML
C# *** 作XML 有以下几种方式:
1:使用XmlDocument相关类库和方法 *** 作xml
2:使用XDocument相关类库和方法 *** 作xml
3:使用XmlReader和XmlWriter相关类库和方法 *** 作xml
1:使用XmlDocument
XmlDocument doc = new XmlDocument();
docLoad("Customer2xml");
// XmlNodeList nodeList = docGetElementsByTagName("row");
XmlNodeList nodeList = docSelectNodes("/Table/row");
//读取属性+元素
foreach (XmlNode item in nodeList)
{
customerInfoAppId = itemAttributes["AppID"]Value;
customerInfoCustomerID = item["CustomerID"]InnerText;
}
2:使用XDocument
XDocument xdoc = XDocumentLoad("Customer2xml");
var custs = from customer in xdocDescendants("row")
select new
{//读取属性+元素
Version = customerAttribute("Version")Value,
CustomerID = customerElement("CustomerID")Value,
};
3:使用XmlReader
XmlReader reader = XmlReaderCreate("Customer2xml", settings);
//读取属性
while (readerRead())
{
if (readerNodeType == XmlNodeTypeElement)
{
switch (readerName)
{
case "row":
customerInfo = new CustomerInfo();
if (readerHasAttributes)
{
customerInfoAppId = readerGetAttribute("AppID");
customerInfoVersion = readerGetAttribute("Version");
}
break;
case "CustomerID":
customerInfoCustomerID = readerReadString();
break;
}
}
java中获取xml节点元素值 根据不同的处理xml方式不同而不同。 java中解析xml的方式:大体可以使用以下四种 ------------------------------------------------------------ DOM(Document Object Model) 为 XML 文档的已解析版本定义了一组接口
读取:
public void GetValue(string value,string date)
{
XmlDocument doc = new XmlDocument();
string path = "";
string title = "";
string body = "";
string bl = "";
path = SystemAppDomainCurrentDomainBaseDirectory;//获取文件路径
docLoad(path + "\\dbGuestxml");
XmlNode node = docSelectSingleNode("dbGuest");
XmlNodeList list = nodeChildNodes;
foreach (XmlNode xn in list)
{
XmlElement xe = (XmlElement)xn;
XmlNodeList xnf1 = xeChildNodes;
foreach (XmlNode xn2 in xnf1)
{
if (xeGetAttribute("days") == value && xeGetAttribute("date") == date)//读取属性
{
if (xn2Name == "title")//获得标题
{
title = xn2InnerText;
}
if (xn2Name == "body")//获得内容
{
body = xn2InnerText;
}
if (xn2Name == "bl")
{
bl = xn2InnerText;
}
}
}
}
lblmesText = title;
txtbodyText = body;
txtwcdText = bl;
}
保存:
private void btnComfrim_Click(object sender, EventArgs e)
{
string path = "";
// string title = "";
if (txtwcdText == "")
{
lblshowmesText = "任务完成度不能为空";
txtwcdFocus();
lblshowmesText = "";
}
XmlDocument doc = new XmlDocument();
try
{
path = SystemAppDomainCurrentDomainBaseDirectory;//获取文件路径
docLoad(path + "\\dbGuestxml");
XmlNode node = docSelectSingleNode("dbGuest");
XmlNodeList list = nodeChildNodes;
foreach (XmlNode xn in list)
{
XmlElement xe = (XmlElement)xn;
XmlNodeList xnf1 = xeChildNodes;
foreach (XmlNode xn2 in xnf1)
{
if (xeGetAttribute("days") == valueToString())//读取属性
{
if (xn2Name == "body")//获得内容
{
xn2InnerText = txtbodyText;
}
else if (xn2Name == "bl")
{
xn2InnerText = txtwcdText;
}
if (xn2Name == "title")
{
xn2InnerText = lblmesText;
}
xeSetAttribute("date",DateTimeNowToString("yyyy-MM"));
}
}
}
docSave(path + "\\dbGuestxml");
lblshowmesText = "提示:任务已成功提交!";
}
catch (Exception ex)
{
}
}
根据你的情况去修改下代码吧,这是我之前用的,可对节点进行修改。
XmlDocument xml = new XmlDocument();
xmlLoad("RSSChannelXML");//加载文件
XmlNode xmlNode = xmlDocumentElement;//获取根节点
foreach (XmlNode node in xmlNodeChildNodes)//获取第一个子节点
{
TreeNode newNode = treeView1NodesAdd(nodeAttributes[0]ValueToString());//获取节点第1个属性的值
foreach (XmlNode node1 in nodeChildNodes)
{
newNodeNodesAdd(node1Attributes[0]ValueToString());//获取子子节点第1个属性的值
newNodeTag = node1InnerText;
}
}
以上就是关于JDOM, 想要获得某个节点内的 全部xml格式的 内容,怎么做.全部的内容,包括:JDOM, 想要获得某个节点内的 全部xml格式的 内容,怎么做.、C# *** 作XML,如何获取指定节点值、如何在VBScript中获取XML文件中节点的内容等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)