2626import org .xml .sax .SAXNotSupportedException ;
2727import org .xml .sax .SAXParseException ;
2828import org .xml .sax .XMLReader ;
29+ import org .xml .sax .helpers .DefaultHandler ;
2930
3031@ SuppressWarnings ({"deprecation" })
3132public 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