core-java icon indicating copy to clipboard operation
core-java copied to clipboard

java-xml/PrintAllHandlerSax incorrect handling of nested nodes

Open rambilde opened this issue 2 years ago • 0 comments

When you add printing value of staff node, it turns out that it has the value of the last nested node (bio):

@Override
    public void endElement(String uri,
                           String localName,
                           String qName) {
...
        if (qName.equalsIgnoreCase("staff")) {
            System.out.printf("staff : %s%n", currentValue.toString());
        }
}

console before:

End Element : bio
Bio : HTML tag <code>testing</code>
End Element : staff
Start Element : staff
Staff id : 1002

console after:

Bio : HTML tag <code>testing</code>
End Element : staff
staff : HTML tag <code>testing</code>
Start Element : staff
Staff id : 1002

rambilde avatar Oct 03 '23 15:10 rambilde