amstyles
Goto Top

XPATH Befehl SVG Java

Hallo Foren User,

ich möchte eine SVG Grafik über DOM einlesen.
Bei einem XML funktioniert das ohne Probleme, da ich in einem Beispieldokument keine Unterknoten habe.
Bei meiner SVG Grafik sieht das so aus.

<svg
.
.
.
.
<g
     inkscape:label="Ebene 1"  
     inkscape:groupmode="layer"  
     id="layer1"  
     transform="translate(0,-752.36218)">  
    <rect
       style="fill:#0000ff;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"  
       id="rect2985"  
       width="94.827583"  
       height="94.827583"  
       x="31.896551"  
       y="13.793103"  
       transform="translate(0,752.36218)" />  
</g>
</svg>

Wie komme ich nun an die einzelnen Metadaten (width, heigtht...) heran?
Im moment versuche ich es über eine XPath Funktion.

    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setNamespaceAware(true); // never forget this!
    DocumentBuilder builder = domFactory.newDocumentBuilder();
    Document doc = builder.parse("c:\\myfile.xml");  

    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();
    XPathExpression expr = xpath.compile("//book[author='Neal Stephenson']/title/text()");  

Über "XPathExpression expr = xpath.compile("//g/rect");" funktiont es nicht.

Danke & Grüße,
AMStyles

Content-Key: 180099

Url: https://administrator.de/contentid/180099

Printed on: April 24, 2024 at 04:04 o'clock