如何在此xml文件中插入/删除节点 [英] how to insert/delete a node to this xml file

查看:93
本文介绍了如何在此xml文件中插入/删除节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:)

我在网上搜索以找到可从该xml文件中插入和删除节点的代码

但是我没有找到像这样的文件的代码

这是我的文件

hi all :)

I search in web to find a code that insert and delete nodes from this xml file

but I didn''t find codes for file like this

here is my file

<netclub rows="2" columns="6">
	<items>
			<item>
				<image src="photos/netclub/sample1.jpg" />
				<description> <![CDATA[<title>Photo Description: Photo 1 </title>Photo Description<a href="event:http://www.zise.com.au/"> Link </a> </description>
			</item>
			
			<item>
				<image src="photos/netclub/sample2.jpg" />
				<description> <![CDATA[<title>Photo Description: Photo 2 </title>Photo Description<a href="event:http://www.zise.com.au/"> Link </a> </description>
			</item>
			
			<item>
				<image src="photos/netclub/sample3.jpg" />
				<description> <![CDATA[<title>Photo Description: Photo 3 </title>Photo Description<a href="event:http://www.zise.com.au/"> Link </a> </description>
			</item>
			
			<item>
				<image src="photos/netclub/sample4.jpg" />
				<description> <![CDATA[<title>Photo Description: Photo 4 </title>Photo Description<a href="event:http://www.zise.com.au/"> Link </a> </description>
			</item>
			
			<item>
				<image src="photos/netclub/sample5.jpg" />
				<description> <![CDATA[<title>Photo Description: Photo 5 </title>Photo Description<a href="event:http://www.zise.com.au/"> Link </a> </description>
			</item>
			
			<item>
				<image src="photos/netclub/sample6.jpg" />
				<description> <![CDATA[<title>Photo Description: Photo 6 </title>Photo Description<a href="event:http://www.zise.com.au/"> Link </a> </description>
			</item>
		
	</items>
 
</netclub>



你能帮我吗?

以及如何在我的站点上创建一个新的xml文件并将其保存到特定文件夹?


谢谢大家:)



can you help me ?

and how can I create a new xml file at my site, and save it to specific folder ?


thank you all :)

推荐答案

整个方法是错误的.尝试为这样的文件查找代码"的习惯是什么?如果在所有情况下都能找到所需的代码,则没有人需要您的工作.创建代码,找不到它.

在这种情况下,您可以在几个不同的级别上工作.这是简短的概述:

The whole approach is wrong. What''s the habit to try to "find codes for file like this"? If the code you need can be found somewhere in all cases, nobody needs your work. Create code, not find it.

In this case, you can work on several different levels. Here is the short overview:


  1. 使用System.Xml.XmlDocument类.它实现了DOM接口;如果文档太大,则这种方法最简单,也足够好.
    请参见 http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx [ http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [http://msdn.microsoft.com/en-us/library/bb387063.aspx [

  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^].
  2. Use the classes System.Xml.XmlReader and System.Xml.XmlWriter; this is the fastest way of reading, especially is you need to skip some data.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^].
  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].



此外,您很多人根本不想手动使用XML,而是使用 Data Contract 的序列化.我强烈建议您使用数据合约.

请参阅
http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ].

另请参阅我过去的答案,我主张使用这种功能强大且非侵入性的方法:
如何在我的表单应用程序? [ ^ ],
创建属性文件... [



Besides, you many want not to use XML manually at all but use serialization of Data Contract instead. I strongly recommend using Data Contract.

See http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

See also my past answer where I advocate using this powerful and non-intrusive approach:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating a property files...[^].

—SA




在这里,我提供了一些用于处理xml文件操作的链接

http://www.codeproject.com/KB/cpp/parsefilecode.aspx

还有

http://www.codeproject.com/KB/XML/genericxml.aspx

您可以使用c#
创建任何文件
http://forums.asp.net/t/1440889.aspx/1

只需检查这些链接,您便可以找到更好的解决方案


所有最好的
Hi,

Here I''m providing some links for handling xml file operations

http://www.codeproject.com/KB/cpp/parsefilecode.aspx

And

http://www.codeproject.com/KB/XML/genericxml.aspx

And you can create any file using c#

http://forums.asp.net/t/1440889.aspx/1

Just check these links you can find better solution


All the Best


那很好

但我想添加一个像这样的新节点

that''s so good

but I want to add a new node like this one

<item>
                <image src="photos/netclub/sample1.jpg" />
                <description> <![CDATA[<title>Photo Description: Photo 1 </title>Photo Description<a href="event:http://www.zise.com.au/"> Link </a> </description>
            </item>



不喜欢这个



not like this one

<name gender="Male">
    <firstname>Tom</firstname>
    <lastname>Smith</lastname>
  </name>



:\

如何在同一个节点上添加更多属性,如

图像的src

您可以通过一些代码来帮助我吗?

谢谢



:\

how can I add more attributes to the same node like

src for image

can you help me doing that by some code, please ?

thank you


这篇关于如何在此xml文件中插入/删除节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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