Dowemo

1 problem description

In developing a java class and xml assembly code, there are three minor problems before the use of the tools.

1. 1 * * one is the leaf value of the node display * *.

After the study, I end through
@ XmlJavaTypeAdapter ( nullstringadapter. Class ).
Define a leaf node similar to nullstringadapter. Class, and then you can get the form of xml output you want by overriding the unmarshall and marshall methods, as follows:


package yang.toxml;


import javax.xml.bind.annotation.adapters.XmlAdapter;


public class NullStringAdapter extends XmlAdapter<String, Boolean> {


 @Override


 public Boolean unmarshal(String v) throws Exception {


 if("".equals(v)) {


 return true;


 }


 return false;


 }


 @Override


 public String marshal(Boolean v) throws Exception {


 if(v) {


 return null;


 }


 return "";


 }


}






1. 2 second: special container node type conve ion.

A problem with the problem is that the complex structure transformation, a complex java structure, hope to change the content in the xml display when the xml display


public class NullStringAdapter extends XmlAdapter<String, Boolean>






I think the extended parsing method for this XmlAdapter, the first argument for generics can only be string, that's: The adapter provides a bridge with an xml string and java class conversion, which makes it possible for me to complete the code quickly and also implement the xml of this special class hierarchy, but there are three problems: In the resulting xml, some strange elements have occurred, the> or <number does show that the & amp; lt; and & amp; gt; and so on, the string xml

1. 3 problems: Xml printing & amp; lt; and & amp; gt;

The problem is that the console printing will see many of the> <numbers that are the lower nodes that use XmlAdapter adaptation to the lower level of the node I.

There are three problems encountered. When I solve the first time, we find a good solution. The second time, there are some, ignoring some better attempts.

A learning machine that's missing from 2 planer.

2. 1 XmlAdapter method overrides.


public class NullStringAdapter extends XmlAdapter<String, Boolean>






All jaxb types inherit from XmlAdapter, which is defined as follows:


public abstract class XmlAdapter<ValueType,BoundType> {






First, it isn't a fixed value for the generic input parameter, and I've written a lot of problems with the code on the internet. The inertia thinking treats the first argument only as string, and I've missed a more flexible problem, and I completed the problem and confirmed that the problem was successful:


package yang.toxml;


import javax.xml.bind.annotation.adapters.XmlAdapter;


public class NullStringAdapter extends XmlAdapter<DataDing, Boolean> {


 @Override


 public Boolean unmarshal(DataDing v) throws Exception {


 if("".equals(v)) {


 return true;


 }


 return false;


 }


 @Override


 public DataDing marshal(Boolean v) throws Exception {


 DataDing ding = new DataDing("true","false");


 return ding;


 }


}






Analysis cause:
A inertia thinking, to assume that a class isn't fully understood, not to view the relevant class descriptions, nor do you've to build a project to make a
B test and try not to be sufficient;

2. 2 xml escape character learning.

& amp; lt; & amp; gt;,, <> & amp; xml,,,,, class1 class2, xml, adapter string, marshall,,"". Replace ("~ ~ ~"),,.
Analysis cause:
1, a continuous of the problem is encountered;
2, there's no, google, and, which is why I decide to restart the blog, continue to summarize the reasons for the development process, and the problem must!

3 summary.

A, the least problem is a continuous problem, always keep patient and explore the center, to solve a problem, and it can keep the sensitivity, knowing that it's!
B, keep google and baidu, to find a small problem that may affect that big problem, may be a little problem.
C, the scheme isn't there. It's a to learn the improvement, to find a better one.




Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs