on 04-29-2013 3:42 PM
Hi
I have to read the XML dynamically , please see the input and expected output
Input:
String inputPayload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<records xsi:type=\"Opportunity\">"
+ "<Id>ABCD</Id>"
+ "<Amount>1000.0</Amount>" + "</records>";
Output
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
< data>
<Object name> Opportunity </Object name>
<records>
<FiledName>ID</FiledName>
<FiledValue>ABCD</FiledValue>
<records>
<records>
<FiledName>Amount</FiledName>
<FiledValue>1000.0</FiledValue>
<records>
< /data>
Please note that the tags Opportunity, ID,Amount etc are dynamic.
Can you please tell how to read this using DOM/SAX or any other method?
Hi Sam,
pretty easy with xsl
The loop with: xsl:for-each "select=//records" (read all records elements) and
xsl:for-each "select="./*" (read all children of a records-element)
Read field values with normal xsl:value-of
Read field names with xsl:value-of select="local-name()"
/Udo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As Udo mentioned xsl mapping is easier. If you want to know how to approach using java mapping. I might want you to see this link.. Your requirement is pretty simpler. Here the example uses sax parser. You will find the code sample which is for beginner to understand like how to retrieve each tag element and how to construct new tag element for the output. If you could tweak the code , you will be able to make it. If you are new to java development, take help from the java team.
Hi Sam,
How are you receiving this input? Is it part of XML payload ? Is this the entire XML you are receiving? This needs small java mapping code to convert it to target XML.
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Experts ..can you please give your suggestions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.