How to capture both content and attribute of a element

View: New views
2 Messages — Rating Filter:   Alert me  

How to capture both content and attribute of a element

by varma111 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi

          I have a problem in capturing the both content and attribute of an element , for e.x

          <image type="pdf">JVskdfsdGYIBUB BBHBUJBBBVvuvvv</image>  this is the way i am expecting.

The Pojo calss of the image is
 

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "content"
})
@XmlRootElement(name = "image")
public class image {

    @XmlValue
    protected String content;

    @XmlAttribute(required = true)
    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
    @XmlSchemaType(name = "NMTOKEN")
    protected String type;


    public String getContent() {
        return content;
    }

    public void setContent(String value) {
        this.content = value;
    }

    public String getType() {
        return type;
    }

    public void setType(String value) {
        this.type = value;
    }

}
   

  But i am getting like this.

     <image type="pdf">
          <content>JVskdfsdGYIBUB BBHBUJBBBVvuvvv</content>
     </image>  
   
  even i set xstream.processAnnotations(image.class); but No use.
 
  i guess i am missing some sort of xstream setting , please let me know how i can overcome this problem.

  Thanks in Advance

Thanks & Regards
Ravi varma  

Re: How to capture both content and attribute of a element

by Jörg Schaible-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Ravi,

varma111 wrote:

>
> Hi
>
>           I have a problem in capturing the both content and attribute of
>           an
> element , for e.x
>
>           <image type="pdf">JVskdfsdGYIBUB BBHBUJBBBVvuvvv</image>  this
>           is
> the way i am expecting.
>
> The Pojo calss of the image is
>  
>
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "", propOrder = {
>     "content"
> })
> @XmlRootElement(name = "image")
> public class image {
>
>     @XmlValue
>     protected String content;
>
>     @XmlAttribute(required = true)
>     @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
>     @XmlSchemaType(name = "NMTOKEN")
>     protected String type;
>
>
>     public String getContent() {
>         return content;
>     }
>
>     public void setContent(String value) {
>         this.content = value;
>     }
>
>     public String getType() {
>         return type;
>     }
>
>     public void setType(String value) {
>         this.type = value;
>     }
>
> }
>    
>
>   But i am getting like this.
>
>      <image type="pdf">
>           <content>JVskdfsdGYIBUB BBHBUJBBBVvuvvv</content>
>      </image>

This is how XStream serializes the object to XML. If you want a member of a
type beeing directly the value of the tag, you have to write a custom
converter. Have a look at the converter tutorial, It's easy. BTW, this
question was already asked two days ago here on the list ...

>   even i set xstream.processAnnotations(image.class); but No use.

Why should it? Thoses annotations are completely unknown to XStream.

>   i guess i am missing some sort of xstream setting , please let me know
>   how
> i can overcome this problem.

Answer in lined.

- Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email