FYI: here is patch that augments XMLLocator to allow reporting parser absolute
character position
in current entity and uses this capability to augment XNI pipeline to report start
tag and end tag positions.
thanks,
alek
Index: src/org/apache/xerces/impl/XMLDocumentFragmentScannerImpl.java
===================================================================
RCS file:
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/impl/XMLDocumentFragmentScannerImpl.java,v
retrieving revision 1.4
diff -u -b -t -w -r1.4 XMLDocumentFragmentScannerImpl.java
--- src/org/apache/xerces/impl/XMLDocumentFragmentScannerImpl.java 2001/11/26
21:45:50 1.4
+++ src/org/apache/xerces/impl/XMLDocumentFragmentScannerImpl.java 2001/12/11
08:46:26
@@ -293,6 +293,25 @@
/** Default constructor. */
public XMLDocumentFragmentScannerImpl() {} // <init>()
+ // ALEK augmentation names to record start tag and end tag event position in
input
+ public final String POS_ABSOLUTE_START =
"http://www.gjt.org/xpp/pos-absolute-start"; //ALEK
+ public final String POS_ABSOLUTE_END =
"http://www.gjt.org/xpp/pos-absolute-end"; //ALEK
+
+ private void recordPosAbsoluteStart(String functionName, int off) {
+ int posAbsoluteStart = fEntityScanner.getCurrentEntityAbsoluteOffset() +
off; //ALEK
+ if (DEBUG_CONTENT_SCANNING) System.out.println(
+ ">>> "+functionName+" recorded position absolute
start="+posAbsoluteStart);
+ fAugmentations.putItem(POS_ABSOLUTE_START, new Integer(posAbsoluteStart));
//ALEK
+ }
+
+ private void recordPosAbsoluteEnd(String functionName, int off) {
+ int posAbsoluteEnd = fEntityScanner.getCurrentEntityAbsoluteOffset() +
off; //ALEK
+ if (DEBUG_CONTENT_SCANNING) System.out.println(
+ ">>> "+functionName+" recorded position absolute
end="+posAbsoluteEnd);
+ fAugmentations.putItem(POS_ABSOLUTE_END, new Integer(posAbsoluteEnd));
//ALEK
+ }
+
+
//
// XMLDocumentScanner methods
//
@@ -697,6 +716,9 @@
throws IOException, XNIException {
if (DEBUG_CONTENT_SCANNING) System.out.println(">>> scanStartElement()");
+ //ALEK record absolute position of start tag including '<'
+ recordPosAbsoluteStart("scanStartElement()", -1); //ALEK
+
// name
if (fNamespaces) {
fEntityScanner.scanQName(fElementQName);
@@ -741,6 +763,9 @@
} while (true);
+ //ALEK record absolute position of end tag past final '>'
+ recordPosAbsoluteEnd("scanStartElement()", 0); //ALEK
+
// call handler
if (fDocumentHandler != null) {
if (empty) {
@@ -959,6 +984,9 @@
protected int scanEndElement() throws IOException, XNIException {
if (DEBUG_CONTENT_SCANNING) System.out.println(">>> scanEndElement()");
+ //ALEK record absolute position of end tag including '</'
+ recordPosAbsoluteStart("scanEndElement()", -2); //ALEK
+
// name
if (fNamespaces) {
if (!fEntityScanner.scanQName(fElementQName)) {
@@ -978,6 +1006,9 @@
}
fMarkupDepth--;
+ //ALEK record absolute position of end tag past final '>'
+ recordPosAbsoluteEnd("scanEndElement()", 0); //ALEK
+
// handle end element
int depth = handleEndElement(fElementQName, false);
if (DEBUG_CONTENT_SCANNING) System.out.println("<<< scanEndElement():
"+depth);
Index: src/org/apache/xerces/impl/XMLEntityManager.java
===================================================================
RCS file:
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java,v
retrieving revision 1.10
diff -u -b -t -w -r1.10 XMLEntityManager.java
--- src/org/apache/xerces/impl/XMLEntityManager.java 2001/10/23 08:01:51 1.10
+++ src/org/apache/xerces/impl/XMLEntityManager.java 2001/12/11 08:46:35
@@ -1639,6 +1639,9 @@
/** Count of characters in buffer. */
public int count;
+ /** Absolute offset since origin of buffer */
+ public int offsetZero;
+
//
// Constructors
//
@@ -3012,6 +3015,36 @@
return -1;
} // getColumnNumber():int
+ /**
+ * Return the position of parser in current entity since its beginning.
+ * This position is in number of UTF16 characters since beginning of
+ * reading that entity.
+ *
+ * @return The position in UTF16 characters or -1 if none is available.
+ */
+ public int getCurrentEntityAbsoluteOffset() { //ALEK
+ //return fCurrentEntity != null ? fCurrentEntity.columnNumber : -1;
+ if (fCurrentEntity != null) {
+ if (fCurrentEntity.systemId != null ) {
+ return fCurrentEntity.position + fCurrentEntity.offsetZero;
+ }
+ else {
+ // search for the first external entity on the stack
+ int size = fEntityStack.size();
+ for (int i=size-1; i>0 ; i--) {
+ ScannedEntity firstExternalEntity =
(ScannedEntity)fEntityStack.elementAt(i);
+
+ if (firstExternalEntity.systemId != null) {
+ return fCurrentEntity.position +
firstExternalEntity.offsetZero;
+ }
+ }
+ }
+ }
+
+ return -1;
+ } // getCurrentEntityAbsoluteOffset():int
+
+
//
// Private methods
//
@@ -3037,6 +3070,8 @@
print();
System.out.println();
}
+ // update absolute offset for this entity
+ fCurrentEntity.offsetZero += fCurrentEntity.position - offset;
// read characters
int length = fCurrentEntity.ch.length - offset;
Index: src/org/apache/xerces/impl/XMLScanner.java
===================================================================
RCS file:
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/impl/XMLScanner.java,v
retrieving revision 1.8
diff -u -b -t -w -r1.8 XMLScanner.java
Index: src/org/apache/xerces/util/ErrorHandlerWrapper.java
===================================================================
RCS file:
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/util/ErrorHandlerWrapper.java,v
retrieving revision 1.3
diff -u -b -t -w -r1.3 ErrorHandlerWrapper.java
--- src/org/apache/xerces/util/ErrorHandlerWrapper.java 2001/11/20 21:56:53 1.3
+++ src/org/apache/xerces/util/ErrorHandlerWrapper.java 2001/12/11 08:46:42
@@ -249,6 +249,7 @@
public String getBaseSystemId() { return null; }
public int getColumnNumber() { return fColumnNumber; }
public int getLineNumber() { return fLineNumber; }
+ public int getCurrentEntityAbsoluteOffset() { return -1; }
};
return new XMLParseException(location, exception.getMessage(),
exception.getException());
Index: src/org/apache/xerces/xni/XMLLocator.java
===================================================================
RCS file:
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/xni/XMLLocator.java,v
retrieving revision 1.2
diff -u -b -t -w -r1.2 XMLLocator.java
--- src/org/apache/xerces/xni/XMLLocator.java 2001/08/23 00:35:36 1.2
+++ src/org/apache/xerces/xni/XMLLocator.java 2001/12/11 08:46:42
@@ -85,4 +85,7 @@
/** Returns the column number. */
public int getColumnNumber();
+ /** Returns the parser position counting sizne beginning of entity input. */
+ public int getCurrentEntityAbsoluteOffset();
+
} // interface XMLLocator
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]