查询XML文档
标签:数据访问 ADO.NET
查询XML文档 LINQ to XML类提供属性和方法,返回可查询的类的对象集合。
将XML对象作为LINQ查询对象:
.......
XDocument customers = XDocument.Load(xmlFileName);
var queryResult = from c in customers.Elements() select c.Name;
使用查询成员
1)Element():返回文档 或 片段中的第一个元素。文档的话就返回根元素; 2)Descendants():返回文档 或 片段中的所有子元素(所有级别); 例:queryResults = from c in customers.Descendants() select c.Name; foreach (var item in queryResults.Distinct()) //筛选出不同的元素
Descendants(string)重载: queryResults = from c in customers.Desendants("customer") select c; //查询指定名称的子元素,返回所有customer元素。
3)Ancestors():返回比源元素级别高的一组元素;
4)Attribute():返回当前选中元素的所有属性;
例:queryResults = from c in customers.Descendants("customer").Attributes() select c; //返回customers中所有customer元素的属性值
相关文档:
/// <summary>
/// DataTable-------------------->XML --String
/// </summary>
public static String ToXmlString(DataTable dt)
{
StringWriter tr = new StringWriter();
try
{
dt.WriteXml(tr); ......
from:http://www.xland.com.cn/article/7/81/0804/28778.htm
本类实现:
数据库信息导出:word,excel,json,xml,sql
数据库恢复:从sql,从文件
具体用法:
首先新建测试用数据库mytest,然后在里面建张表
PHP代码:
以下是代码片段:
--
-- 表的结构 `test`
--
CREATE TABLE `test` (
`id ......
XML文件实例:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource auth="Container" maxActive="20" name="sss" password="123"
type="javax.sql.DataSource" />
<Resource auth="Container" ......
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 ......