java - Line number of xinclude while unmarshalling using jaxb -
i found question on so. shows how line numbers of individual xml elements while unmarshalling jaxb. extended example being able use xinclude
. unfortunately, i'm not able line number of xinclude
.
so, how line number of actual xinclude
statement? here extended example:
import java.io.file; import java.io.fileinputstream; import java.io.filenotfoundexception; import java.io.ioexception; import javax.xml.bind.jaxbcontext; import javax.xml.bind.jaxbexception; import javax.xml.bind.unmarshaller; import javax.xml.parsers.parserconfigurationexception; import javax.xml.parsers.saxparserfactory; import javax.xml.transform.sax.saxsource; import org.xml.sax.entityresolver; import org.xml.sax.inputsource; import org.xml.sax.saxexception; import org.xml.sax.xmlreader; public class demo { public static void main(string[] args) throws jaxbexception, saxexception, parserconfigurationexception, filenotfoundexception { jaxbcontext jc = jaxbcontext.newinstance(person.class); unmarshaller unmarshaller = jc.createunmarshaller(); saxparserfactory spf = saxparserfactory.newinstance(); spf.setxincludeaware(true); spf.setnamespaceaware(true); spf.setvalidating(true); file file = new file("src/person.xml"); xmlreader xr = spf.newsaxparser().getxmlreader(); xr.setentityresolver(new entityresolver() { @override public inputsource resolveentity(string publicid, string systemid) throws saxexception, ioexception { system.out.println(publicid + " -> " + systemid); return null; } }); saxsource source = new saxsource(xr, new inputsource( new fileinputstream(file))); person person = (person) unmarshaller.unmarshal(source); system.out.println("person: " + person.locator.getlinenumber()); system.out.println("address: " + person.address.locator.getlinenumber()); } }
the entityresolver
listener tells me there xinclude
statement, don't know on line number.
person.xml
<?xml version="1.0" encoding="utf-8"?> <person xmlns:xi="http://www.w3.org/2001/xinclude"> <name>jane doe</name> <xi:include href="./src/address.xml" /> </person>
address.xml
<?xml version="1.0" encoding="utf-8"?> <address>1 street</address>
i didn't mention person
, address
class, questions stays short , compact :) marked every locator
field @xmltransient
. thank you!
Comments
Post a Comment