SV: [jdom-interest] Line numbers

Bradley S. Huffman hip at cs.okstate.edu
Thu Aug 28 08:56:02 PDT 2003


So back to the original question, wouldn't this work?

    int lineNumber = -1;
    int columnNumber = -1;
    try {
        document = builder.build(file);
    }
    catch(JDOMException je) {
        Throwable cause = je;
        while(cause != null) {
            cause = je.getCause();
            if (cause instanceof SAXParseException) {
                lineNumber = (SAXParseException cause).getLineNumber();
                columnNumber = (SAXParseException cause).getColumnNumber();
                break;
            }
        }
    }

The problem I have with storing line and column info. inside elements is 
after the first modification to the document the info. probably becomes
meaningless.  For example, read in a document, fetch the root element
and do something like

    root.addContent(new Text("\n\n\n"));

What are the line and column numbers of all of root's descendants?

Brad



More information about the jdom-interest mailing list