Usually there no problem using Dom4J to get attribute values from XML Files
Also in XML Tools I can use xsl and Xpath to get the value of "use fill" from that SVG
<svg xmlns="http://www.w3.org/2000/svg" width="2250" height="2700" viewBox="0 0 1800 2160" color-interpolation-filters="sRGB" fill="none" overflow="visible" fill-rule="evenodd" stroke-linecap="square" stroke-miterlimit="3" xmlns:xlink="http://www.w3.org/1999/xlink">
<g transform="translate(363.17-1988.15)">
<use fill="#f00" xlink:href="#1"/>
<g transform="translate(72.59-8.504)">
<use xlink:href="#9"/>
<use xlink:href="#B"/>
<use xlink:href="#A"/>
</g>
<text x="25.29" y="2143.97" fill="#000" font-family="Arial" font-size="8">SetAnnotations</text>
</g>
e.g. that works in xmlSpy
/svg/g/use/@fill or //g[text="SetAnnotations"]/use/@fill
That (and everything else I tried) failed in Java (which usually works)
public static String getNodeValue(Element doc, String xpath){
try{
return doc.selectSingleNode(xpath).getText();
}catch (Exception ex){
log.debug("getNodeValue failed with " + ex.getMessage());
return null;
}
}
or
public static String getAttributeValue(Element doc, String xpath, String attributeName){
try{
Node node = doc.selectSingleNode(xpath);
String value = node.valueOf(attributeName);
return value;
}catch (Exception ex){
log.debug("getAttributeValue failed with " + ex.getMessage());
return null;
}
}
for some reasons I can just use 1.5 + dom4J but as svg is pretty old I would hope for a solution without additional libraries as batik
Any idea how to work correctly with svg's (reading and changing attributes) in Java ?
Thank in advance for any hint