[英]Jaxb unmarshal - elements with minoccurs 0 which should be combined
I have following XML file: 我有以下XML文件:
<?xml version="1.0" encoding="utf-8"?>
<Paragraph>
<ParaStyleName>headline_red</ParaStyleName>
<TextStyleRanges>
<TextStyleRange>
<CharStyleName>[Ohne]</CharStyleName>
<Contents>
<Content>inhalt</Content>
<Content>test text</Content>
<SpecialCharacter name="HARD_RETURN"/>
<Content> "text here</Content>
<SpecialCharacter name="DOUBLE_QUOTE_LEFT"/>
</Contents>
</TextStyleRange>
</TextStyleRanges>
</Paragraph>
From this xml I need to obtain the Content part like this: inhalt test text HARD_RETURN "text here DOUBLE_QUOTE_LEFT 从这个xml中,我需要像这样获得Content部分:吸入测试文本HARD_RETURN“此处的文本DOUBLE_QUOTE_LEFT
For me the tag order inside of <Contents>
is important, problem is that the number of and <SpecialCharacter>
is not always fix, and also the position of this tags is not fixed. 对我来说,
<Contents>
内的标签顺序很重要,问题是<SpecialCharacter>
和<SpecialCharacter>
的数目并不总是固定的,而且此标签的位置也不固定。
Note: I'm using JAXB for this and I have created the Model Class for Contents, for Content and for SpecialCharacter where in Contents I have as members ArrayList<Content>
and ArrayList<SpecialCharacter>
but in this case I can't linked the lists correct to keep the correct order of tags. 注意:为此,我使用JAXB,并且为内容,内容和SpecialCharacter创建了模型类,其中在Contents中我作为成员
ArrayList<Content>
和ArrayList<SpecialCharacter>
但是在这种情况下,我无法链接列出正确的标签以保持正确的标签顺序。
Please HELP me with a solution for this case. 请为我提供这种情况的解决方案。 Thanks!
谢谢!
You are going to need to merge these two lists as follows: 您将需要如下合并这两个列表:
@XmlElements(
@XmlElement(name="Content", type=Content.class),
@XmlElement(name="SpecialCharacter", type=SpecialCharacter.class)
})
public List<Object> getValues() {
return values;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.