虽然五一过了,还是先向大伙问个好~^_^
    小弟毕设,做一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 规范里,发觉不常用的东西太多~谢谢大伙了,:-)

解决方案 »

  1.   

    用XPATH吧,操作起来更灵活一点!
      

  2.   

    http://community.csdn.net/Expert/topic/5402/5402403.xml?temp=.5823786
      

  3.   

    http://www.w3pop.com/tech/school/xpath/default.asp
      

  4.   

    如果我要得到如下表,该怎么写xpath?
    id   SourcePath                     DestinPath
    0    \\192.168.21.64\Share          \\192.168.21.65\Backup
    1    c:\windows\*.*                 \\192.168.21.65\Backup
      

  5.   

    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);
    }
      

  6.   

    http://www.zvon.org/xxl/XPathTutorial/Output/example1.htmlhttp://www.w3pop.com/tech/school/xpath/default.asp
      

  7.   

    to lovefootball:
    有没有方便一点的方法,读取到DataTable中?
      

  8.   

    看一下这段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>
      

  9.   

    谢谢楼上的,我还不懂XSLT,学习中……
      

  10.   

    结贴,我是用xpath,一个节点一个的读~