Add XML Util class

pull/35/head
James Ball 2020-10-24 13:05:55 +01:00
rodzic cc8b7dd39a
commit 0b2565d981
2 zmienionych plików z 33 dodań i 0 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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<Node> asList(NodeList n) {
return n.getLength()==0?
Collections.emptyList(): new NodeListWrapper(n);
}
static final class NodeListWrapper extends AbstractList<Node>
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();
}
}
}