处理XML片段
标签:数据访问 ADO.NET
处理XML片段 处理片段时,只是把XElement(而不是XDocument)当作顶级XML对象。
片段的唯一限制是,不能添加比较节点类型,例如:XComment,XDeclaration,XProcessingInstruction(用于XML处理指令)。
例: XElement xcust = new XElement( new XElement(......)..........);
注意:这两个类都实现了Load()和Save()方法,XElemnt 和 XDocument继承自LINQ to XML类的XContainer; 在XDocument上执行的大多数操作,在XElement上也可以执行。
相关文档:
Definition comparer class,
class ItemComparer : IEqualityComparer<XElement>
{
public bool Equals(XElement x, XElement y)
{
return x.Attribute("Name").Value == x.Attribute("Name").Value;
}
public int GetHashCode(XElement obj)
......
var
xmlDoc
=
null
;
function
parseXML
(
xmlUrl
)
{
try
{
//IE
xmlDoc
=
new
ActiveXObject
(
"Microsoft.XMLDOM"
);
xmlDoc
.
async
=
false
;
xmlDoc
......
public int createXMLFile(String filename) {
int returnValue = 0;
Document document = DocumentHelper.createDocument(); //生成Document,用于管理XML文档
Element booksElement = document.addElement("books"); //添加 ......
package com.jcauto.action;
import java.util.ArrayList;
import java.util.List;
public class ContentRsp {
private String resultCode;
List<ContentInfo> contentList = new ArrayList<ContentInfo>();
public void addContent(ContentInfo contentInfo) {
contentList.add(contentI ......