将多个xml文件合并到单个xml文件中。 [英] Merge mulitple xml files into single xml file.

查看:819
本文介绍了将多个xml文件合并到单个xml文件中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个或多个.xml文件的xml提要。



我必须在jquery scroller中显示这个feed,我使用的是xml数据源控件的datafile属性对于单个.xml文件,



但现在我想从多个.xml文件中滚动来源



如何合并这些多个xml文件并生成单个.xml文件,并将xml daatasource数据文件属性设置为这个新生成的文件..?所以显示所有.xml文件的提要。



任何建议都表示赞赏。



目前我我正在使用xmlreader与数据集合并,它正在工作但我希望它完成xslt传递xml文件urls作为参数到.xslt文件并将所有这些作为一个文件,以便我可以将它绑定到xml数据源。 br />


我不擅长.xslt和那种语法,而且我必须动态地将xml feed urls传递给xslt文件,所有文件都有与rss / channel /相同的xpath item blah ....



如何动态执行此操作。

I have xml feed from one or more .xml files.

I have to show this feed in jquery scroller, I am using datafile property of xml datasource control for single .xml file,

But now I want to scroll feed from multiple .xml files

how can I merge those multiple xml files and produce single .xml file and set the xml daatasource data file property to this newly produced file..? so that feeds from all .xml files are shown.

any suggestion is appreciated.

presently I am using xmlreader with dataset merging, it''s working but I want it done with xslt passing xml file urls as parameters to that .xslt file and making all those as one file, so that I can bind it to the xml datasource.

I am not good at .xslt and that syntax, moreover I have to pass xml feed urls dynamically to the xslt file, all files have same xpath like rss/channel/item blah....

How can I do this dynamically.

推荐答案

没有人单个配方,它取决于每个文件的架构。在某些情况下,XML可能相互矛盾,因此这样的问题可能是可以解决的。一个简单的例子是:合并可以使唯一的属性值(目标文件的模式所需,例如 id )非唯一。



可以采用不同的方法。一个简单的方法是解析所有文件,然后将它们组合到DOM文档中,检查有效性等。当您使用 XmlReader 打开输入文件时,另一种方法可以是仅向前的,一次性或一个一个地使用类 XmlWriter 作为目标文件。



从技术上讲,您可以参考我在.NET FCL上提供的不同XML类的简短概述:



There is no one single recipe, it depends on the schema of each file. In some cases, XML can contradict to each other, so such problem may be solvable or not. One simple example is: merging can make unique attribute values (required by the schema of the target file, such as id) non-unique.

There can be different methods of doing it. A trivial approach is parsing all files and then combining them into a DOM document, checking validity, etc. Another method could be forward-only, when you open input files with XmlReader, all at once or one-by-one and using the class XmlWriter for the target file.

Technically, you can refer to my short overview of different XML classes available on .NET FCL:



  1. 使用 System.Xml.XmlDocument class。它实现了DOM接口;如果文档的大小不是太大,这种方式是最简单和最好的。
    参见 http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [ ^ ]。
  2. 使用类 System.Xml.XmlTextWriter System.Xml.XmlTextReader ;这是最快的阅读方式,特别是你需要跳过一些数据。
    参见 http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx [ ^ ], http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx [ ^ ]。
  3. 使用类系统.Xml.Linq.XDocument ;这是类似于 XmlDocument 的最合适的方式,支持LINQ to XML Programming。
    参见 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.XmlTextWriter and System.Xml.XmlTextReader; 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.xmlwriter.aspx[^], 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[^].





祝你好运,

-SA


这篇关于将多个xml文件合并到单个xml文件中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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