在所需的架构中更改输入XML的格式 [英] Change format of Input XML in desired Schema

查看:62
本文介绍了在所需的架构中更改输入XML的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我是XML转换新手并遇到问题。我希望更改输入XML的XML格式以获得所需的格式。

我的输入XML是



Hi All,

I am new to XML conversion and stuck with a problem. I wish to change XML format of an input XML to get desired format.
My input XML is

<RootNode>
<Person ID="1" Name="Bob Smith" Dept="Risks"> <Address Number="12" PostCode="A12 3BC" Country="UK"/>
</Person>
</RootNode>



和所需输出为:




and output required is :

<RootNode>
<Person ID="1" Name="Bob Smith" Dept="Risks"> <Address Number="12" PostCode="A12 3BC" StreetName="Test Road" Country="UK"/>
</Person>
</RootNode>







任何人都可以给我完整的方法。我是否需要序列化或使用XSLT?




Can anybody give me complete method. Do i need to serialize or use XSLT ??

推荐答案

您在这里所做的实际上是改变XML中的值。查看您的示例,Address有一个名为StreetName的新属性。您需要做的就是读取XML(我将使用XLINQ来完成所有这些),并迭代每个Address元素 - 向元素添加一个新的StreetName XAttribute,然后在完成后将其保存。如果添加StreetName不是您的问题所在,您需要明确告诉我们您要实现的目标。
What you seem to be doing here is actually changing the values that are inside your XML. Looking at your example, Address has a new attribute called StreetName. All you need to do is read in the XML (I would use XLINQ for all of this), and iterate over each Address element - add a new StreetName XAttribute to the element and then save it out when you're done. If adding a StreetName is not what your problem is, you need to explicitly tell us what you are trying to achieve.


这篇关于在所需的架构中更改输入XML的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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