[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xml to json converter

  • From: Mukul Gandhi <mukulg@softwarebytes.org>
  • To: "Liam R. E. Quin" <liam@fromoldbooks.org>
  • Date: Sat, 18 Sep 2021 12:38:17 +0530

Re:  xml to json converter
On Fri, Sep 17, 2021 at 7:40 PM Liam R. E. Quin <liam@fromoldbooks.org> wrote:
 
You might want to compare it to the JSON support built in to XQuery and
XSLT and XPath these days.

Ok. I shall look into this, as I would further explore this topic.
 
Also test  content containing [ ] " { } " '
& < > \ and / as well as element names and content containing non-ascii
characters. <ആൺകുട്ടി>....</ആൺകുട്ടി> or <ARÊT>...</ARÊT>.

I couldn't test with XML element names and content, containing ആൺകുട്ടി for example. Which language is this please?

The other parts I've tested, and it works fine with the same technical pattern that I've described within my original mail on this thread.

Below are further details, that I've tested newly.

The XSD document is,

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="X">
       <xs:complexType>
          <xs:sequence>
             <xs:element name="ARÊT" maxOccurs="unbounded">
               <xs:complexType>
                 <xs:sequence>
                   <xs:element name="b" type="xs:string" maxOccurs="unbounded"/>
                 </xs:sequence>
                 <xs:attribute name="id" type="xs:integer"/>
               </xs:complexType>
             </xs:element>
          </xs:sequence>
       </xs:complexType>
    </xs:element>

</xs:schema>

And the corresponding, XML instance document is,

<?xml version="1.0" encoding="ISO-8859-1"?>
<X>
  <ARÊT id="1">
    <b>hello</b>
    <b>world ARÊT</b>    
  </ARÊT>
  <ARÊT id="2">
    <b>I'm</b>
    <b>[ ] &quot; { } &quot; &apos; &amp; &lt; &gt; \ /</b>    
  </ARÊT>
</X>

Please note following,
a) I now need to specify encoding="ISO-8859-1" within XSD and XML instance documents.
b) As suggested by you, I've specified the text containing [ ] " { } " ' & < > \ and / within XML instance document, encoded as entity references required for XML documents.

The JAXB command xjc, generated file X.java needs following custom change to handle this test case,

public class X {
      @XmlElement(name = "AR\u00caT", required = true)
      @JsonProperty("AR\u00caT")      // we need to add this annotation, for jackson to circumvent default java beans naming convention
      protected List<X.ARÊT> arêt;

Running the same java program, that I've posted earlier within this thread, now produces following JSON result,

{
  "ARÊT" : [ {
    "b" : [ "hello", "world ARÊT" ],
    "id" : 1
  }, {
    "b" : [ "I'm", "[ ] \" { } \" ' & < > \\ /" ],
    "id" : 2
  } ]
}

(I think, jackson JSON serializer correctly escapes special characters)


--
Regards,
Mukul Gandhi


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.