• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting an object into an XML

 
Ramachandran Narayanan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
  • 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: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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?
 
Paul Clapham
Sheriff
Pie
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but that's attribute normalization, which doesn't apply to element values, if I'm not mistaken.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic