使用csharp的XML操作 [英] XML manipulation using csharp

查看:75
本文介绍了使用csharp的XML操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果要删除xml节点,请使用c#在以下xml示例中更新现有节点并添加新节点,该怎么办?

If i want to delete an xml node,update an existing node and add a new node in the following xml sample using c#, what should i do?

<?xml version="1.0" ?>
- <GovTalkMessage xmlns="http://www.govtalk.gov.uk/CM/envelope">
  <EnvelopeVersion>2.0</EnvelopeVersion>
- <Header>
- <MessageDetails>
  <Class>HMRC-VAT-DEC</Class>
  <Qualifier>poll</Qualifier>
  <Function>submit</Function>
  <TransactionID />
  <CorrelationID>1B93D48C02D740C6B79DE68A27F3ADE5</CorrelationID>
  <ResponseEndPoint PollInterval="10">https://secure.dev.gateway.gov.uk/poll</ResponseEndPoint>
  <GatewayTimestamp>2011-04-05T07:41:43.018</GatewayTimestamp>
  </MessageDetails>
  <SenderDetails />
  </Header>
- <GovTalkDetails>
  <Keys />
  </GovTalkDetails>
  <Body />
  </GovTalkMessage>

推荐答案

如果文件相对较小,则最简单的方法是使用DOM.使用System.Xml.XmlDataDocument.

注意:永远不要直接使用XML节点.对于DOM,请阅读完整的XML文档,操作DOM节点(它们与XML元素和属性具有一一对应的关系,但它们并不相同).您将使用的主要类是System.Xml.XmlNode以及派生类.看一看这些课程的帮助;您将立即看到如何操作它们.

—SA
If the files are relatively small, the simplest way is using DOM. Use System.Xml.XmlDataDocument.

Note: you should not ever work with XML nodes directly. In case of DOM, you read full XML document, manipulate DOM nodes (they have one-to-one correspondence with XML Elements and Attributes, but they are not the same). The main class you will work is System.Xml.XmlNode, as well as derived classes. Take a look at the help of those classes; and you will immediately see how to manipulate them.

—SA


成员7794889308写道:
Member 7794889308 wrote:

如果我要删除xml节点,使用c#在以下xml示例中更新现有节点并添加新节点,该怎么办?

If i want to delete an xml node,update an existing node and add a new node in the following xml sample using c#, what should i do?



我建议你看看这个.

使用C#操纵XML文件数据 [ ^ ]



I suggest you take a look at this.

Manipulate XML File Data Using C#[^]


这篇关于使用csharp的XML操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆