Portál AbcLinuxu, 4. listopadu 2025 23:41
< ?xml version="1.0" encoding="UTF-8"? > ... < xi:include href='ServerStructure_Modul_IsMaster.xml'/> .....Potřebuji vytvořit DOM objekt načtením souboru včetně XInclude.
public Document readFromFile() {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setAttribute("http://apache.org/xml/features/xinclude", true); //$NON-NLS-1$
dbf.setXIncludeAware(true);
dbf.setNamespaceAware(true);
DocumentBuilder builder = dbf.newDocumentBuilder();
return builder.parse(this.getClass().getResourceAsStream(fileName));
} catch (Exception ex) {
Logger.getInstance().addLogEvent(new LogEvent(ex));
return null;
}
}
Metoda skončí s chybou
An 'include' failed, and no 'fallback' element was found. org.xml.sax.SAXParseException: An 'include' failed, and no 'fallback' element was found. at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source) at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)Jak na to dál. Řešil to někdo? Mohlo by pomoci uvést SystemId String do volání builder.parse(this.getClass().getResourceAsStream(fileName), systemId);?. Díky za každé nakopnutí.
URL a to můžete parseru předat také (po převedení na String).
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.