How to get jaxb to Ignore certain data during unmarshalling

后端 未结 3 1536
面向向阳花
面向向阳花 2020-12-11 22:39

I have a xml structure \"Filter\" that get unmarshalled into in a java class called \"Filter\".

The XML state looks roughly like:


  &         


        
3条回答
  •  感情败类
    2020-12-11 23:22

    How about the annotation of using "@XmlAnyElement"? You can get the instance of org.w3c.dom.Element. The text data should be able to be obtained by operating this instance.

    class PropertyType {
        private String propertyName;
        // private String propertyValue; // comment out
        @XmlAnyElement(lax=true)
        private List propertyValue; // Adding this
    }
    

    exsample of to get text data.

    // It is assumed that the child node is one. 
    org.w3c.dom.Node nd = propertyValue.get(0).getFirstChild();
    while(true) {
        if (nd.hasChildNodes()) {
            nd = nd.getFirstChild();
        } else {
            System.out.println(nd.getNodeValue()); // this is text data
            break;
        }
    }
    

提交回复
热议问题