mirror of
https://github.com/processing/processing4.git
synced 2026-02-11 17:40:48 +01:00
several XML fixes
This commit is contained in:
@@ -62,61 +62,59 @@ public class XML implements Serializable {
|
||||
* Begin parsing XML data passed in from a PApplet. This code
|
||||
* wraps exception handling, for more advanced exception handling,
|
||||
* use the constructor that takes a Reader or InputStream.
|
||||
* @throws SAXException
|
||||
* @throws ParserConfigurationException
|
||||
* @throws IOException
|
||||
*/
|
||||
public XML(PApplet parent, String filename) {
|
||||
public XML(PApplet parent, String filename) throws IOException, ParserConfigurationException, SAXException {
|
||||
this(parent.createReader(filename));
|
||||
}
|
||||
|
||||
|
||||
public XML(File file) {
|
||||
public XML(File file) throws IOException, ParserConfigurationException, SAXException {
|
||||
this(PApplet.createReader(file));
|
||||
}
|
||||
|
||||
|
||||
public XML(Reader reader) {
|
||||
public XML(Reader reader) throws IOException, ParserConfigurationException, SAXException {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
|
||||
// Prevent 503 errors from www.w3.org
|
||||
try {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
|
||||
// Prevent 503 errors from www.w3.org
|
||||
factory.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ignore this; Android doesn't like it
|
||||
}
|
||||
|
||||
// without a validating DTD, this doesn't do anything since it doesn't know what is ignorable
|
||||
// without a validating DTD, this doesn't do anything since it doesn't know what is ignorable
|
||||
// factory.setIgnoringElementContentWhitespace(true);
|
||||
|
||||
factory.setExpandEntityReferences(false);
|
||||
factory.setExpandEntityReferences(false);
|
||||
// factory.setExpandEntityReferences(true);
|
||||
|
||||
// factory.setCoalescing(true);
|
||||
// builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
// builder.setEntityResolver()
|
||||
|
||||
// SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
// spf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||
// SAXParser p = spf.newSAXParser();
|
||||
|
||||
// builder = DocumentBuilderFactory.newDocumentBuilder();
|
||||
// builder = new SAXBuilder();
|
||||
// builder.setValidation(validating);
|
||||
// builder = DocumentBuilderFactory.newDocumentBuilder();
|
||||
// builder = new SAXBuilder();
|
||||
// builder.setValidation(validating);
|
||||
|
||||
// print(dataPath("1broke.html"), System.out);
|
||||
|
||||
// Document document = builder.parse(dataPath("1_alt.html"));
|
||||
Document document = builder.parse(new InputSource(reader));
|
||||
node = document.getDocumentElement();
|
||||
name = node.getNodeName();
|
||||
Document document = builder.parse(new InputSource(reader));
|
||||
node = document.getDocumentElement();
|
||||
name = node.getNodeName();
|
||||
// NodeList nodeList = document.getDocumentElement().getChildNodes();
|
||||
// for (int i = 0; i < nodeList.getLength(); i++) {
|
||||
// }
|
||||
// print(createWriter("data/1_alt_reparse.html"), document.getDocumentElement(), 0);
|
||||
|
||||
} catch (ParserConfigurationException pce) {
|
||||
pce.printStackTrace();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
} catch (SAXException e2) {
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -154,7 +152,12 @@ public class XML implements Serializable {
|
||||
|
||||
|
||||
static public XML parse(String xml) {
|
||||
return new XML(new StringReader(xml));
|
||||
try {
|
||||
return new XML(new StringReader(xml));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user