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.
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)?
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Joined: Feb 26, 2010
I am using the Apache API.
The object Mapping looks like this:
<element name = "ErrorList">
<element ref = "q:ErrorCode"/>
<element ref = "qErrorMessage"/>(where i need to display the message with the whitespaces)
and <element name = "ErrorCode" type = "string"/>
<element name = "ErrorMessage" type = "string"/>
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?
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.