get text using JAXB

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

get text using JAXB

alberto.cogolludo
Hi

In my app, I'm reading a xml file (with JAXB) but there is times that I
have empty segments.

I put some examples

<tuv>
    <seg>Unknown: the action taken should always be known</seg>
   </tuv>
Here I read well the tag "seg", I can get all text "Unknown: the action
taken should always be known" but if this text is like this:

<tuv>
    <seg><bpt i="1" x-wb-tag="b1" />Unknown<ept i="1" x-wb-tag="/b1"
/>: the action taken should always be known</seg>
   </tuv>
I don't get anything, my variable is empty and I want to get all text
"<bpt i="1" x-wb-tag="b1" />Unknown<ept i="1" x-wb-tag="/b1" />: the
action taken should always be known"

Could I get this text "<bpt i="1" x-wb-tag="b1" />Unknown<ept i="1"
x-wb-tag="/b1" />: the action taken should always be known" or only
"Unknown: the action taken should always be known" (without tag "ept"
and "bpt"? (I want this like a string)

Note: my variable's value is a "string"

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: get text using JAXB

Mirko Klemm
Hi Alberto,
it seems what you are trying to do is process a so-called „mixed content“ element with JAXB.

JAXB handles this as a property of type „List<E>“, where „E“ can be of several types.

I suggest you refer to the documentation, like this one:

https://jaxb.java.net/tutorial/section_2_2_12_7-Mixed-Content.html

to get more info about this.
Regards,
Mirko

> Am 2015-02-25 um 11:40 schrieb [hidden email]:
>
> Hi
>
> In my app, I'm reading a xml file (with JAXB) but there is times that I
> have empty segments.
>
> I put some examples
>
> <tuv>
>    <seg>Unknown: the action taken should always be known</seg>
>   </tuv>
> Here I read well the tag "seg", I can get all text "Unknown: the action
> taken should always be known" but if this text is like this:
>
> <tuv>
>    <seg><bpt i="1" x-wb-tag="b1" />Unknown<ept i="1" x-wb-tag="/b1"
> />: the action taken should always be known</seg>
>   </tuv>
> I don't get anything, my variable is empty and I want to get all text
> "<bpt i="1" x-wb-tag="b1" />Unknown<ept i="1" x-wb-tag="/b1" />: the
> action taken should always be known"
>
> Could I get this text "<bpt i="1" x-wb-tag="b1" />Unknown<ept i="1"
> x-wb-tag="/b1" />: the action taken should always be known" or only
> "Unknown: the action taken should always be known" (without tag "ept"
> and "bpt"? (I want this like a string)
>
> Note: my variable's value is a "string"
>
> Thanks!


smime.p7s (4K) Download Attachment