XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] 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]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS