Как найти атрибут XMLElement, когда XMLElement не является RootElement, без использования XPath - PullRequest
0 голосов
/ 05 августа 2020

Это мои свойства. xml

<properties>
    <property>
        <source pattern = "../a">
        <target pattern = "../b>
        <target pattern = "../c>
    </property>
</properties>

У меня есть файл свойств, помеченный @XMLRootElement, как это

Свойства. java

@XmlRootElement(name = "properties")
@XmlAccessorType(XmlAccessType.FIELD)
public class Properties {
    
    @XmlElement(name="property")
    private final List<Property> properties = new ArrayList<>();

}

Свойство. java

@XmlRootElement(name = "property")
@XmlAccessorType(XmlAccessType.FIELD)
public class Property {
    
    @XmlElement(name="source") /* **I want to directly assign the attribute of this XMLElement to the variable** */
    private String srcPattern;
    
    @XMLElement(name="target") /* **I want to directly assign the attribute of this XMLElement to the variable** */
    private List<String> targetPatterns;

}

Как мне присвоить значение атрибута source переменной scrPattern и targetPattern - targetPatterns? Без использования XPath

...