3

my xml file is below:

<ExternalCases>
    <ignoreTag>
        <CashLess>
            <caseType>CashLess</caseType>
            <claimNo>9</claimNo>
            <status>Open</status>
        </CashLess>
    </ignoreTag>
</ExternalCases>

i want to ignore <ignoreTag> and i want <CashLess> tag in my Unmarshaller process.

my class like below:

@XmlRootElement(name="ExternalCases")
public class ExternalCases {

    List<CashLess> cashLess;

    @XmlElement(name="CashLess", required=false)
    public List<CashLess> getCashLess() {
        return cashLess;
    }
    public void setCashLess(List<CashLess> cashLess) {
        this.cashLess = cashLess;
    }
}

Thanks.

1
  • Cool question, is about my issue
    – Andremoniy
    Commented Nov 10, 2015 at 13:19

2 Answers 2

4

Ignoring ignoreTag

You could create a StAX filtered XMLStreamReader and have JAXB unmarshal that to ignore one or more XML elements.

Below is a link to a full example I gave in an answer to a similar question:

If ignoreTag is a Grouping Element

If instead ignoreTag is a grouping element for the collection then you could map it as:

@XmlElementWrapper(name="ignoreTag")
@XmlElement(name="CashLess", required=false)
public List<CashLess> getCashLess() {
    return cashLess;
2
  • it is working but instead of particular tag i want general solution. in place of <ignoreTag> any tag will come. Commented Feb 12, 2014 at 12:11
  • 1
    @Rajesh - General solution then would be to use the StreamFilter.
    – bdoughan
    Commented Feb 12, 2014 at 12:13
0

Use answers of these questions::

JAXB ignoring xml tag attribute

JAXB - Ignore element

might be helpful!!!

1
  • my thing is, i don't want to delete entire <ignoreTag> tag, just ignore <ignoreTag> tag and need to populate <CashLess> content. Commented Feb 12, 2014 at 12:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.