lukas-krecan / json2xml

Java JSON to XML converter
Apache License 2.0
64 stars 26 forks source link

JSON to XML dont add attributes #2

Closed nandini1509 closed 12 years ago

nandini1509 commented 12 years ago

In this code i found that Json to xml conversion if json contain @attribute how do i add that if it encounter @attibute it create as elemnt not attribute...

output:-

<@ProductRef ProductRef="ProductRef1">ProductRef1 Actual result :- Provide me solution for it... Thanks
lukas-krecan-gdc commented 12 years ago

I am not sure I understand. Could you please attach a test case?

nandini1509 commented 12 years ago

As I am still developing the code I am stuck with the attributes stuff..

Actually in my json has attributes are also there

I am not able to add that attributes to the element as I have given above example...my attribute comes as element were I need to add to previous element...

R u still not clear what I actually want ?

lukas-krecan commented 12 years ago

If I understand it correctly, you need convert JSON like this http://stackoverflow.com/questions/5957371/is-use-of-attributes-in-json-non-standard-or-standard to XML? I will try to figure something out.

lukas-krecan commented 12 years ago

I have been thinking about your problem and the only solution I see is to apply an XSLT transformation on the resulting XML. Unfortunately it would be really hard to implement support for @attribute to json2xml. The reason is simple. json2xml works in streaming mode - it reads JSON and emits SAX events right away. The @attribute element can be encountered when the XML element start tag is already rendered.

To reiterate, it's not likely that I will add support for attributes to json2xml, but you can create a simple XSLT template that would solve your problem.

nandini1509 commented 12 years ago

Yes , thanks for reply...but can u give me an smalexample with that how does that work...and I have different kind of json to be converted....to xml....

nandini1509 commented 12 years ago

I think with xslt its not possible...I have different type of xml to be generated....and if I use any library it give me random order of xml which fail schema validation....so just help me out with better solutions...

lukas-krecan-gdc commented 12 years ago

I still think that XSLT is the best solution for you. Using XSLT you can generate XML with correct order of elements and tailor the conversion to your specific needs.

Random order of XML is probably caused by the fact that JSON does not have to preserve order of nodes.

You have to ask XSLT or XML related questions somewhere else, I do not have time to help you with json2xml unrelated problems.

nandini1509 commented 12 years ago

Thanks