虽然五一过了,还是先向大伙问个好~^_^
小弟毕设,做一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 规范里,发觉不常用的东西太多~谢谢大伙了,:-)
小弟毕设,做一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 规范里,发觉不常用的东西太多~谢谢大伙了,:-)
id SourcePath DestinPath
0 \\192.168.21.64\Share \\192.168.21.65\Backup
1 c:\windows\*.* \\192.168.21.65\Backup
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);
}
有没有方便一点的方法,读取到DataTable中?
<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>