I'm looking to consume an svg image and parse/process the different paths to do a custom conversion. What is the easiest way, in Java, to simply extract the path data? I was looking at the apache xmlgraphics/batik packages, but it's not real obvious how to return the path types and parameters. Any suggestions?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
To simply extract the
path
data you can use XPath.Suppose you have this SVG and you want to extract all the
path
data (from bothpath
elements):You first load the XML as a Document:
Then you use XPath to select the desired nodes. The expression below selects the contents of the
d
attributes of all thepath
elements inside the file:Now we can instantiate the XPath processor and compile the expression:
Since the expected result is a node-set (two strings), we evaluate the expression on the SVG document using
XPathConstants.NODESET
as the second parameter:From there you can extract the first set of path data using: