读书人

关于XPath(不知道在哪问了暂时放这

发布时间: 2012-01-30 21:15:58 作者: rapoo

关于XPath(不知道在哪问了,暂时放这儿:-))
虽然五一过了,还是先向大伙问个好~^_^
小弟毕设,做一Windows Service程序(用于局域网内的文件传输),其需要的参数由前台Winform配置;中间参数的存储是由XML来完成。其结构:
<Paras>
<Task id= "0 ">
<Path>
<SourcePath> \\192.168.21.64\Share </SourcePath>
<DestinPath> \\192.168.21.65\Backup </DestinPath>
</Path>
<Account>
<SourceAccount>
<UserName> pqmagic </UserName>
<Password> 123 </Password>
</SourceAccount>
<DestinAccount>
<UserName> administrator </UserName>
<Password> 123 </Password>
</DestinAccount>
</Account>
<FileLimit>
<TypeLimit enable= "false ">
<Type> .txt </Type>
</TypeLimit>
<SizeLimit enable= "false ">
<MinSize> 0 </MinSize>
<MaxSize> 10 </MaxSize>
</SizeLimit>
</FileLimit>
<TransferMode>
<StartTime> 2007-04-28 15:58:00 </StartTime>
<Interval> 0 </Interval>
</TransferMode>
<FileName>
<Prefix enable= "false ">
</Prefix>
<Postfix> CurrentTime </Postfix>
<!--CurrentTime,FourRankNum,FourRaiseNum-->
</FileName>
</Task>
<Task id= "1 ">
<Path>
<SourcePath> c:\windows\*.* </SourcePath>
<DestinPath> \\192.168.21.65\Backup </DestinPath>
</Path>
<Account>
<SourceAccount>
<UserName> pqmagic </UserName>
<Password> 123 </Password>
</SourceAccount>
<DestinAccount>
<UserName> administrator </UserName>
<Password> 123 </Password>
</DestinAccount>
</Account>
<FileLimit>
<TypeLimit enable= "false ">
<Type>
</Type>
<Type>
</Type>
</TypeLimit>
<SizeLimit enable= "false ">
<MinSize> 0 </MinSize>
<MaxSize> 10 </MaxSize>
</SizeLimit>
</FileLimit>
<TransferMode>
<StartTime> 2007-04-28 15:58:00 </StartTime>
<Interval> 0 </Interval>
</TransferMode>
<FileName>
<Prefix enable= "false ">
</Prefix>
<Postfix> CurrentTime </Postfix>
<!--CurrentTime,FourRankNum,FourRaiseNum-->
</FileName>
</Task>
</Paras>
目前遇到以下问题:
1,参数的结构化读取困难。要获取其中一些特节点(或节点属性),来构成一个新的二维表很麻烦。用DataSet读入xml时,里面的DataTable有限,不能满足需求。如果用Xpath来分别获取单个节点(或节点属性),然后自己填充DataTable又太麻烦。
2,参数的添加,删除麻烦。其实也是同样的问题,如果用DataSet操作,由于各个DataTable之间的约束关系,操作起来也不方便。
我刚接触XML,对其理解很浅。麻烦大家指点迷津,用DataSet实现好,还是用Xpath?同时也敬请告知一下常用的Xpath语法,自己找的Xpath 规范里,发觉不常用的东西太多~谢谢大伙了,:-)

[解决办法]
采用序列化
[解决办法]
用XPATH吧,操作起来更灵活一点!
------解决方案--------------------


http://community.csdn.net/Expert/topic/5402/5402403.xml?temp=.5823786
[解决办法]
http://www.w3pop.com/tech/school/xpath/default.asp
[解决办法]
XPath在W3C上有介绍

XmlDocument doc = new XmlDocument();
doc.Load( "e:\\1.xml ");//初始化XmlDocument
XmlNodeList list = doc.SelectNodes( "/Paras/Task ");
foreach (XmlNode node in list)
{
Console.WriteLine(node.Attributes[ "id "].Value);
XmlNode temp1 = node.SelectSingleNode( "Path/SourcePath ");
Console.WriteLine(temp1.InnerText);
XmlNode temp2 = node.SelectSingleNode( "Path/DestinPath ");
Console.WriteLine(temp2.InnerText);
}
[解决办法]
http://www.zvon.org/xxl/XPathTutorial/Output/example1.html

http://www.w3pop.com/tech/school/xpath/default.asp
[解决办法]
看一下这段XSLT代码跟你要的一样吗??

<?xml version= "1.0 " encoding= "GB2312 " ?>
<xsl:stylesheet xmlns:xsl= "http://www.w3.org/TR/WD-xsl ">
<xsl:template match= "/ ">
<html>
<head>
<title> </title>
</head>
<body>
<table border= "1 ">
<xsl:apply-templates select= "Paras/Task/Path " />
</table>
</body>
</html>
</xsl:template>

<xsl:template match= "Paras/Task/Path ">
<xsl:apply-templates select= "Task "/>
<tr>

<th>
<xsl:value-of select= "SourcePath "/>
</th>
<th>
<xsl:value-of select= "DestinPath "/>
</th>
</tr>
</xsl:template>
<xsl:template match= "Task ">
<xsl:value-of select= "@id "/>
</xsl:template>
</xsl:stylesheet>

读书人网 >C#

热点推荐