Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.7k views
in Technique[技术] by (71.8m points)

java - Cut text when using @XmlAnyElement

This is my xml file:

<v1:clippings xmlns:v1="v1.clipping.pure.atira.dk" xmlns:commons="v3.commons.pure.atira.dk">
    <v1:clipping id="xxx">
        <v1:type>exportcomment</v1:type>
        <v1:title>Hemmelig lyttestation udvider i Hj?rring</v1:title>
        <v1:description>
            <commons:text lang="da" country="DK"> Professor p? Forsvarsakademiet, <b>Peter Viggo Jakobsen</b>, siger til Jyllandsposten, at det giver god mening at opgradere overv?gningskapaciteten af ...

</v1:clippings>

I'm trying to get the lang attribute and the value of commons:text

I wrote these class:

@XmlAccessorType(XmlAccessType.FIELD)
public class Clipping {

    @XmlElement(name = "type", namespace = "v1.clipping.pure.atira.dk")
    public String type;

    @XmlElement(name = "title", namespace = "v1.clipping.pure.atira.dk")
    public String title;

    @XmlElement(name = "description", namespace = "v1.clipping.pure.atira.dk")
    public ClippingDescription description;


@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "description", namespace = "v1.clipping.pure.atira.dk")
public class ClippingDescription {

    @XmlElement(name = "text", namespace = "v3.commons.pure.atira.dk")
    public ClippingDescriptionText text;

}

@XmlAccessorType(XmlAccessType.FIELD)
public class ClippingDescriptionText {

    @XmlAnyElement(ClippingDescriptionHandler.class)
    public String text;

    @XmlAttribute
    public String lang;

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

}

The output I'm getting for the lang is correct (da), but the value of the text is cut I'm only getting: ?xml version="1.0" encoding="UTF-8"?>Peter Viggo Jakobsen</b"

I dubbugged ClippingDescriptionHandler class, the input of the getElement method is already cut. Any suggestions?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...