Skip to content

Commit dd35a50

Browse files
hansonrhansonr
authored andcommitted
SAX XML fixes
1 parent ebdada6 commit dd35a50

File tree

6 files changed

+35
-16
lines changed

6 files changed

+35
-16
lines changed
4.01 MB
Binary file not shown.
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
<<<<<<< HEAD
2-
20180820200147
3-
=======
4-
20180820101854
5-
>>>>>>> branch 'yadav1' of https://github.com/BobHanson/java2script.git
1+
20180820232825
4.01 MB
Binary file not shown.
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
<<<<<<< HEAD
2-
20180820200147
3-
=======
4-
20180820101854
5-
>>>>>>> branch 'yadav1' of https://github.com/BobHanson/java2script.git
1+
20180820232825

sources/net.sf.j2s.java.core/src/javax/xml/parsers/SAXParserFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public SAXParser newSAXParser() {
9494
for (Object name : props.keySet()) {
9595
r.setProperty((String) name, props.getProperty((String)name));
9696
}
97+
} else if (p instanceof org.xml.sax.XMLReader) {
98+
org.xml.sax.XMLReader r = (org.xml.sax.XMLReader) p;
99+
for (Object name : props.keySet()) {
100+
r.setProperty((String) name, props.getProperty((String)name));
101+
}
97102
}
98103
return p;
99104
} catch (Exception e) {

sources/net.sf.j2s.java.core/src/swingjs/JSSAXParser.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.xml.sax.SAXNotSupportedException;
2727
import org.xml.sax.SAXParseException;
2828
import org.xml.sax.XMLReader;
29+
import org.xml.sax.helpers.DefaultHandler;
2930

3031
@SuppressWarnings({"deprecation"})
3132
public class JSSAXParser implements Parser, XMLReader {
@@ -62,7 +63,7 @@ public void setErrorHandler(ErrorHandler handler) {
6263
this.errorHandler = handler;
6364
}
6465

65-
public void parse(InputSource source, JSSAXContentHandler handler) throws SAXException, IOException {
66+
public void parse(InputSource source, DefaultHandler handler) throws SAXException, IOException {
6667
setContentHandler(handler);
6768
parseSource(source);
6869
}
@@ -122,12 +123,12 @@ private DOMNode parseXML(String data) {
122123
* @return reconfigured data
123124
*/
124125
private String removeProcessing(String data) {
125-
if (data.indexOf("<?") >= 0) {
126+
if (false && data.indexOf("<?") >= 0) { // doesn't seem to be necessary?
126127
getUniqueSequence(data);
127128
data = PT.rep(PT.rep(data, "<?", "<![CDATA[" + uniqueSeq), "?>", "]]>");
128129
if (data.startsWith("<!")) {
129-
data = "<pre>" + data + "</pre>";
130-
havePre = true;
130+
data = "<pre>" + data + "</pre>";
131+
havePre = true;
131132
}
132133
}
133134
return data;
@@ -153,8 +154,10 @@ private void error(Exception e) throws SAXException {
153154
private boolean ver2;
154155

155156

157+
private static final int ELEMENT_TYPE = 1;
158+
156159
/**
157-
* early Jmol method allowing reading data from an XHTML document
160+
* Using JQuery to reading data from an XHTML document
158161
*
159162
* @param doc
160163
* @throws SAXException
@@ -167,7 +170,26 @@ private void parseDocument(DOMNode doc) throws SAXException {
167170
contentHandler.startDocument();
168171
else
169172
docHandler.startDocument();
170-
walkDOMTree((DOMNode) DOMNode.getAttr(doc, "firstChild"), havePre);
173+
174+
// We must continue down until we have the root node.
175+
176+
DOMNode element = (DOMNode) DOMNode.getAttr(doc, "firstChild");
177+
178+
// skipping type 8 (processing directive) and type 10 (doctype) and anything
179+
// that is not 1 (element)
180+
181+
/**
182+
* @j2sNative
183+
*
184+
* var type;
185+
* while (element && (type = element.nodeType) != 1) {
186+
* element = element.nextSibling;
187+
* }
188+
*
189+
*/
190+
191+
192+
walkDOMTree(element, havePre);
171193
if (ver2)
172194
contentHandler.endDocument();
173195
else

0 commit comments

Comments
 (0)