如何替换XML元素的值

时间:2010-12-15 13:08:04

标签: xml c#-4.0

我有这个XML文档

    <?xml version="1.0" encoding="utf-8" ?>
<session name ="tdsls4401m000">
  <parameters>
    <!-- any of the fields can be specified as parameter : unspecified field values will be take from there default -->
    <parameter name="ornoFrom" target="/session/fields/field[@name='orno.f']" type ="string" >1</parameter>
    <parameter name="ornoTo" target="/session/fields/field[@name='orno.t']" type ="string" >141527</parameter>
    <parameter name="device" target="/session/verbs/setreport/parameter[@name='device']" type="string">123</parameter>
    <!--<parameter name="compFrom" target="/session/fields/field@name[comp.f]" type ="string" >000</parameter>
    <parameter name="compTo" target="/session/fields/field@name[comp.t]" type ="string" >999</parameter>-->

  </parameters>
  <fields>
    <field name="selection" verb="setenum"  debug="true">1</field>
    <field name="orno.f" verb="put"  debug="true"></field>
    <field name="orno.t" verb="put"  debug="true"></field>
    <field name="comp.f" verb="put"></field>
    <field name="comp.t" verb="put"></field>
    <field name="prnt.discount" verb="put" value="2"></field>
    <field name="prnt.sellpr" verb="put" value="2"></field>
    <field name="printed" verb="put" value="1"></field>
    <field name="quan.to.print" verb="put" value="1"></field>
    <field name="prnt.options" verb="put" value="2"></field>
    <field name="num.copies" verb="put" value="1"></field>
  </fields>
  <verbs>
    <setreport>
      <parameter name="reportname">"rtdsls440101000"</parameter>
      <parameter name="device">"105"</parameter>
    </setreport>
    <continue/>
  </verbs>
</session>

现在我需要使用参数元素中包含的值提取每个/ session / parameter @ target node(axis)值。

这样做的最佳方法是什么?

谢谢

1 个答案:

答案 0 :(得分:0)

您可以使用xml解析库:它将允许您了解xml文档的任何节点和变量的值。我不知道c#有哪些库,但对于c ++,有TinyXml。看一下,也许这是.net语言的端口。