• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Converting an object into an XML

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an object which is mapped to an XML.The object has a String variable whose value is "Lines requested is above the maximum of %3d "(12 white spaces)

In the above message I expect a 12 character white space after the error message. I have tried adding the white spacing in the code. But when the response XML is build using the XML Schema that is provided, the white spaces are trimmed.

Is there some way to solve this?

Thanks
Ramachandran
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which API are you using to map the object to an XML representation? What does the object mapping look like exactly (for the String member at the very least)?
 
Ramachandran Narayanan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using the Apache API.

The object Mapping looks like this:

<element name = "ErrorList">
<complexType>
<sequence>
<element ref = "q:ErrorCode"/>
<element ref = "qErrorMessage"/>(where i need to display the message with the whitespaces)
</sequence>
</complexType>
</element>

and <element name = "ErrorCode" type = "string"/>
<element name = "ErrorMessage" type = "string"/>
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The schema definition indicates that the element only content model applies, in which case it's possible that the parser implementation, if in validating mode, will trim ignorable whitespaces from the element's content. Not sure how likekly that is though. You said that you're using "the Apache API". By that do you mean XMLBeans? Could you post the code that invokes the API that write the Object graph to the XML file? Are you absolutely sure that, before writing the String value to the XML file it does, in fact, contain the 12 trailing white spaces?
 
Sheriff
Posts: 28362
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the XML Recommendation, the section about attribute value normalization:

If the attribute type is not CDATA, then the XML processor MUST further process the normalized attribute value by discarding any leading and trailing space (#x20) characters, and by replacing sequences of space (#x20) characters by a single space (#x20) character.

 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, but that's attribute normalization, which doesn't apply to element values, if I'm not mistaken.
 
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic