Skip to content

Commit

Permalink
WIP for properly tracking line numbers in JRuby.
Browse files Browse the repository at this point in the history
Related to #1223.
  • Loading branch information
flavorjones committed Sep 30, 2015
1 parent ebdb95b commit f435981
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ext/java/nokogiri/internals/NokogiriDomParser.java
Expand Up @@ -39,6 +39,12 @@
import org.apache.xerces.parsers.DOMParser;
import org.apache.xerces.parsers.XIncludeParserConfiguration;
import org.apache.xerces.xni.parser.XMLParserConfiguration;
import org.apache.xerces.xni.XMLLocator;
import org.apache.xerces.xni.NamespaceContext;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;
import org.apache.xerces.xni.Augmentations;
import org.cyberneko.dtd.DTDConfiguration;
import org.w3c.dom.Document;
import org.xml.sax.Attributes;
Expand All @@ -57,6 +63,7 @@ public class NokogiriDomParser extends DOMParser {
protected DOMParser dtd;
protected boolean xInclude;
protected XMLParserConfiguration config;
protected XMLLocator locator;

public NokogiriDomParser(XMLParserConfiguration config) {
super(config);
Expand Down Expand Up @@ -113,4 +120,21 @@ public InputSource resolveEntity(String publicId, String systemId)
return source;
}
}

@Override
public void startDocument(XMLLocator locator,
String encoding,
NamespaceContext namespaceContext,
Augmentations augs) {
this.locator = locator;
super.startDocument(locator, encoding, namespaceContext, augs);
}

@Override
public void startElement(QName element,
XMLAttributes attributes,
Augmentations augs) {
System.out.println(element + ": " + locator.getLineNumber());
super.startElement(element, attributes, augs);
}
}

0 comments on commit f435981

Please sign in to comment.