diff --git a/src/parser/SvgParser.java b/src/parser/SvgParser.java index 72b31c4..cb25b81 100644 --- a/src/parser/SvgParser.java +++ b/src/parser/SvgParser.java @@ -8,6 +8,7 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; +import org.w3c.dom.Node; import org.xml.sax.SAXException; import shapes.Shape; @@ -33,6 +34,8 @@ public class SvgParser extends FileParser { DocumentBuilder builder = factory.newDocumentBuilder(); File file = new File(path); Document doc = builder.parse(file); + + for (Node elem : doc.getElementsByTagName("path")) } @Override diff --git a/src/parser/XmlUtil.java b/src/parser/XmlUtil.java new file mode 100644 index 0000000..8d87a51 --- /dev/null +++ b/src/parser/XmlUtil.java @@ -0,0 +1,30 @@ +package parser; + +import java.util.AbstractList; +import java.util.Collections; +import java.util.List; +import java.util.RandomAccess; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public final class XmlUtil { + private XmlUtil(){} + + public static List asList(NodeList n) { + return n.getLength()==0? + Collections.emptyList(): new NodeListWrapper(n); + } + static final class NodeListWrapper extends AbstractList + implements RandomAccess { + private final NodeList list; + NodeListWrapper(NodeList l) { + list=l; + } + public Node get(int index) { + return list.item(index); + } + public int size() { + return list.getLength(); + } + } +}