This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Services and the fly likes XML message is not created properly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "XML message is not created properly" Watch "XML message is not created properly" New topic
Author

XML message is not created properly

Elango Valluvan
Greenhorn

Joined: May 02, 2005
Posts: 8
Using the .xsd files provided to me, I created XMLBeans using the schema project in weblogic 8.1 sp2. (I am using "xbean.jar" of BEA)

These XMLBeans are used to create a XML document in my Weblogic Integration process. The values in the xml document are retrieved from a database (which cannot administered/viewed by me). XML document was formed perfectly. But recently when I tried running the application again, I found that the xml is not created properly.

When I tried to print the xml message, it displays the xml message with the first letter changed from '<' to '&1t;'.

eg.
<batch_document>
.....
...
</batch_document> is displayed as

&1t;batch_document>
...
..
</batch_document>


What may be the reason behind this change. Is it possible because of some invalid data from the backend? If so, what could be the data?
Is there any special characters which when inserted between the elements makes the document like this?

I would be grateful even if I am answered with any of these questions.

Thanks in advance.
[ March 14, 2006: Message edited by: Elango SV ]
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Elango SV:
XML document was formed perfectly. But recently when I tried running the application again, I found that the xml is not created properly.


Well, what has changed? (if anything).
I believe you are seeing '&lt;' not '&1t;' (a lowercase L rather than a �one� ; i.e. the less-than entity).

Because of the special meaning of <, > , and & in XML, these characters cannot be used in the content portion of an XML element. So whenever <, >, & are used in text they need to be replaced by &lt; , &gt; and &amp; respectively.

You may have to encode the strings before your put them into your object representation of the XML document. Fortunately BEA has already provided that functionality in a library method - XMLUtils.encodeXML(String,boolean). That also means that you will have to run XMLUtils.decodeXML(String) on any text coming from the object representation or the XML document.

Alternately one of your development, editing or printing tools may have inadvertently changed the '<' to a '&lt;'.
[ March 14, 2006: Message edited by: Peer Reynders ]
Elango Valluvan
Greenhorn

Joined: May 02, 2005
Posts: 8
Thanks a lot for your reply.

I very well know that the special characters when used in content portion will be converted to its equivalent entity references.

I think you have misunderstood my question. The change from '<' to '&1t;' is not happening in the data portion (or content portion). It is happening at the element tag (i.e. at <batch_document> tag). Strange...right??

The '<' character in the start element tag is converted to '&1t;' making the whole xml document completely invalid.

I am using weblogic workshop for development. The code that creates the xml document goes like this ...

BatchDocumentDocument bDoc= BatchDocumentDocument.Factory.newInstance();
BatchDocument bd= bDoc.addNewBatchDocument();
...
..

System.out.println(bDoc.toString());

The print statement prints the xml message as

&1t;batch_document> ----> change happens here in the element tag
....
..
</batch_document>

Note: I have used 1 instead of l in the text 'lt;' because the forum displays it as '<'.


[ March 15, 2006: Message edited by: Elango SV ]
[ March 15, 2006: Message edited by: Elango SV ]
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Elango SV:
I think you have misunderstood my question. The change from '<' to '&1t;' is not happening in the data portion (or content portion). It is happening at the element tag (i.e. at <batch_document> tag). Strange...right??


No, I didn't misunderstand. However none of us know the exact logic in that document object. They may allow XML fragments as content that become part of the document upon serialization without further encoding. If that is the case then the serialization logic may get confused if there are <, >, & characters in your normal text content. The text preceding 'batch_document' may contain a '<' which it interprets to be the beginning of an opening tag so the real opening angle bracket is rendered as an '&lt;'
(Still haven't figured out how to get '&lt;' and using '&1t;' instead?)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML message is not created properly
 
Similar Threads
Read a .xls,.xlsx file format using XSSF
checking valid data input using DOM/XMLBeans
RMI experts-> createRegistry and a stupid argument...
Unable to retrieve html format data using XML Beans
handling multiple languages using XSL