Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

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

and output required is :

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



Can anybody give me complete method. Do i need to serialize or use XSLT ??
Posted
Updated 24-Jan-14 0:04am
v2
Comments
Tejas Vaishnav 24-Jan-14 6:07am    
where you are stuck? have your right any code in which you got error, then please share that code block too.

and from your input and out put XML, i think you are trying to add streetName to your address node, am i right? if so then what is your code block, please use improve question functionality and add your code block.

1 solution

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.
 
Share this answer
 
Comments
vicvis 24-Jan-14 6:50am    
I understood what you are saying and i probabbly got the direction to think upon.Actually this was a sample code.My basic problem was that I am getting an XML from a third party but i need to change its format as all attribute in the incoming XML need to be converted as XML Elements.Also,I need to remove few attributes and few elements need to be added in XML.I was thinking to go by serialisation or XSLT but not preety sure if that could work.
But Thanks a lot,I think I can use your advice and by some modification,could try to find solution.

Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900