处理不同结构和不同名称的xml文件
我有一个方法,我希望不同的用户向我传递 xml 文件。对于我正在寻找的元素,这些文件将具有不同的名称,并且我正在寻找的元素可能具有不同的结构。我的第一印象是我们应该告诉他们以标准格式传递 xml。然而,这就是他们获取数据的方式,并且他们坚持认为,如果不需要转换数据,就会容易得多。
我可以做什么来获取所有类型的数据?
他们有通过字典吗? number = mydata/numbers
他们向我定义数据而不实际更改数据的最简单方法是什么?
样品1
<numbers>
15
</numbers>
样品2
<mydata>
<mynumbers>
15
</mynumbers>
</mydata>
I have a method and I want different users to pass me xml files. These files will have different names for the elements I am looking for and the elements I am looking for maybe at different structures. My first impression was that we should just tell them to pass in the xml in a standard format. However this is how they have their data and they insist that it is much easier if they don't have to convert it.
What can I do to take in data of all types?
Have them pass in a dictionary?
number = mydata/numbers
What is the easiest way for them to define their data to me without actually changing it?
sample1
<numbers>
15
</numbers>
sample2
<mydata>
<mynumbers>
15
</mynumbers>
</mydata>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
LINQ to XML 可以非常轻松地处理不同格式的文档。例如,此查询将获取您提到的两个文档的“15”:
LINQ to XML can handle documents of varying format quite easily. For example this query will get the "15" for both the documents you mentioned: