Xmlbean is indeed a very convenient tool. It can generate Java classes based on XSD, so that we can read and write XML in a very comfortable object-oriented way. the xmldocument and xmlnode objects in the net world are more intuitive. However, the documents in the Java World are not flattering. Code The crude Java Doc produced is treated as API ref and cannot be compared with Microsoft's msdn. This is when I use multiple Java development tools and Lib, this impression has been deepened again and again.
Some time ago, I used xmlbean to generate xml strings. My process was like this: 1. I used xmlspy to write the XSD and then used xmlbean to generate a Java class for me. 2. Use these Java classes to create a document. The data source is database 3. Obtain the XML string of the generated document. 3. Adapt to Web service to send these XML strings to a remote server. 4. The remote server verifies the received XML based on XSD to check whether it complies with the specifications. As a result, the remote server ( Program Is written by another company, but the same XSD is used.) The verification fails. After checking, I found that the node labels of the XML Element generated by xmlbean are not exactly the same as those defined in XSD. For example, I defined in XSD:
< Xs: Element Name = "Myverylongtagname" >
The generated XML is
< Mvltn > </ Mvltn >
On the surface, xmlbean generates the abbreviated form of tag for me, which is not what I want. I checked the crude Java Doc of xmlbean and tried multiple APIs to solve the problem. Now I will list the small tip: to ensure that the Tag Name of the generated XML element is exactly the same as that defined in XSD, You Need To Do additional work, such: Myxmldocument Doc = Myxmldocument. Factory. newinstance ();
// Create and set XML node Value
// Set xmloptions
Xmloptions OPT = New Xmloptions ();
Map = New Hashmap ();
Map. Put ( " My XML namespace " , " Xmlnsnameinxml " );
Map. Put ( " My element Tag Name " , " Elementtagnameinxml " );
// Set use implicit namespaces
Opt. setsaveimplicitnamespaces (MAP );
// Get XML string
String xmlstring = Doc. xmltext (OPT );
After this setting, xmlbean will not intelligently set the long element Tag Name and xml ns defined in XSD as simple abbreviations.