Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6609475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:43:21+00:00 2026-05-25T19:43:21+00:00

I am using the XMLSerializer found in the json-lib library, in order to transform

  • 0

I am using the XMLSerializer found in the json-lib library, in order to transform between JSON and XML and back.

Is there anyway to avoid the <e> and <a> nodes, that are generated? This is very inconveniently ruining by path-expressions?

Consider the example below:

{"store": {
  "book":   [
        {
      "category": "reference",
      "author": "Nigel Rees",
      "title": "Sayings of the Century",
      "price": 8.95
    },
        {
      "category": "fiction",
      "author": "Evelyn Waugh",
      "title": "Sword of Honour",
      "price": 12.99
    },
        {
      "category": "fiction",
      "author": "Herman Melville",
      "title": "Moby Dick",
      "isbn": "0-553-21311-3",
      "price": 8.99
    },
        {
      "category": "fiction",
      "author": "J. R. R. Tolkien",
      "title": "The Lord of the Rings",
      "isbn": "0-395-19395-8",
      "price": 22.99
    }
  ],
  "bicycle":   {
    "color": "red",
    "price": 19.95
  }
}}

Is serialised into:

<?xml version="1.0" encoding="UTF-8"?>
<o>
  <store class="object">
    <bicycle class="object">
      <color type="string">red</color>
      <price type="number">19.95</price>
    </bicycle>
    <book class="array">
      <e class="object">
        <author type="string">Nigel Rees</author>
        <category type="string">reference</category>
        <price type="number">8.95</price>
        <title type="string">Sayings of the Century</title>
      </e>
      <e class="object">
        <author type="string">Evelyn Waugh</author>
        <category type="string">fiction</category>
        <price type="number">12.99</price>
        <title type="string">Sword of Honour</title>
      </e>
      <e class="object">
        <author type="string">Herman Melville</author>
        <category type="string">fiction</category>
        <isbn type="string">0-553-21311-3</isbn>
        <price type="number">8.99</price>
        <title type="string">Moby Dick</title>
      </e>
      <e class="object">
        <author type="string">J. R. R. Tolkien</author>
        <category type="string">fiction</category>
        <isbn type="string">0-395-19395-8</isbn>
        <price type="number">22.99</price>
        <title type="string">The Lord of the Rings</title>
      </e>
    </book>
  </store>
</o>

Something like what this http://jsontoxml.utilities-online.info/ provides would have been exactly what I’m after, but don’t seem to be available in Java.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:43:22+00:00Added an answer on May 25, 2026 at 7:43 pm

    You can do this with StAXON – JSON via StAX. StAXON implements the Streaming API for XML, but reads and writes JSON. That is, you can use standard XML tools to do the Job.

    A common “trick” to copy XML is using an identity XML transformation (XSLT).

    Here’s some code:

    InputStream input = ... // your JSON input;
    OutputStream output = System.out;
    try {
        /*
         * Create source.
         */
        XMLInputFactory inputFactory = new JsonXMLInputFactory();
        inputFactory.setProperty(JsonXMLInputFactory.PROP_MULTIPLE_PI, false);
        Source source = new StAXSource(inputFactory.createXMLStreamReader(input));
    
        /*
         * Create result.
         */
        XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
        XMLStreamWriter writer = outputFactory.createXMLStreamWriter(output);
        writer = new PrettyXMLStreamWriter(writer); // format output
        Result result = new StAXResult(writer);
    
        /*
         * Transform (copy).
         */
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        transformerFactory.newTransformer().transform(source, result);
    } finally {
        /*
         * As per StAX specification, XMLStreamReader/Writer.close() doesn't close
         * the underlying stream.
         */
        output.close();
        input.close();
    }
    

    Running this with your example produces:

    <?xml version="1.0" ?>
    <store>
        <book>
            <category>reference</category>
            <author>Nigel Rees</author>
            <title>Sayings of the Century</title>
            <price>8.95</price>
        </book>
        <book>
            <category>fiction</category>
            <author>Evelyn Waugh</author>
            <title>Sword of Honour</title>
            <price>12.99</price>
        </book>
        <book>
            <category>fiction</category>
            <author>Herman Melville</author>
            <title>Moby Dick</title>
            <isbn>0-553-21311-3</isbn>
            <price>8.99</price>
        </book>
        <book>
            <category>fiction</category>
            <author>J. R. R. Tolkien</author>
            <title>The Lord of the Rings</title>
            <isbn>0-395-19395-8</isbn>
            <price>22.99</price>
        </book>
        <bicycle>
            <color>red</color>
            <price>19.95</price>
        </bicycle>
    </store>
    

    Note: If the output property PROP_MULTIPLE_PI is set to true, StAXON will generate <xml-multiple> processing instructions. These can be used by StAXON when converting back to JSON to trigger array starts. Leave this set to false if you don’t need to go back to JSON.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using XmlSerializer to deserialize Xml achives. But I found the class xsd.exe generated
I am using XmlSerializer to write and read an object to xml in C#.
I'm having a hard time trying to indent XML files using XMLSerializer . I've
I'm using an XmlSerializer to deserialize a particular type in mscorelib.dll XmlSerializer ser =
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
I found a problem with the XML Serialization of C#. The output of the
In a recent project I'm using a lot of databinding and xml-serialization. I'm using
I'm currently using XmlSerializer to, surprisingly enough :), handle de/serialization of my data structures
I'm currently using an XMLSerializer to serialize a list of a class of my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.