Load xml file "weak"-schema-aware
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 280
- Joined: Thu Nov 28, 2013 9:32 am
- Location: Hamburg/Germany
- Contact:
Load xml file "weak"-schema-aware
Hi,
I'm using ParserCreator.newSchemaAwareDocumentBuilder() to load the complete book in my custom framework from java. Now it occurs quite often, that a small (and easily recoverable) bug in the xml code (non-unique id, missing included file, missing mandatory element, ...) keeps the file from being loaded. Since I hardly need the default attributes to be added I can't use a non-schema-aware document builder as well.
Since oXygen can handle these document pretty well when opening them in author mode, I'm wondering if there is a way to load such files with expanded default attributes but without validation from within my java extension as well.
Thanks and regards,
Patrik
I'm using ParserCreator.newSchemaAwareDocumentBuilder() to load the complete book in my custom framework from java. Now it occurs quite often, that a small (and easily recoverable) bug in the xml code (non-unique id, missing included file, missing mandatory element, ...) keeps the file from being loaded. Since I hardly need the default attributes to be added I can't use a non-schema-aware document builder as well.
Since oXygen can handle these document pretty well when opening them in author mode, I'm wondering if there is a way to load such files with expanded default attributes but without validation from within my java extension as well.
Thanks and regards,
Patrik
-
- Posts: 1016
- Joined: Wed Nov 16, 2005 11:11 am
Re: Load xml file "weak"-schema-aware
Post by alex_jitianu »
Hello Patrik,
It appears that the default error handler is the one that when notified, decides to trow an exception. You can set an error handler that just ignores the received notifications:
where the handler looks like this:
Best regards,
Alex
It appears that the default error handler is the one that when notified, decides to trow an exception. You can set an error handler that just ignores the received notifications:
Code: Select all
DocumentBuilder newDocumentBuilder = ParserCreator.newSchemaAwareDocumentBuilder();
newDocumentBuilder.setErrorHandler(new NoErrorsReportedHandler());
Code: Select all
public class NoErrorsReportedHandler implements XMLErrorHandler, ErrorHandler {
@Override
public void warning(String p0, String p1, XMLParseException ex) throws XNIException {
// Consumes warnings.
}
@Override
public void error(String p0, String p1, XMLParseException ex) throws XNIException {
// Consumes errors.
}
public void fatalError(String p0, String p1, XMLParseException ex) throws XNIException {
}
@Override
public void warning(SAXParseException ex) throws SAXException {
}
@Override
public void error(SAXParseException ex) throws SAXException {
}
@Override
public void fatalError(SAXParseException ex) throws SAXException {
}
}
Best regards,
Alex
-
- Posts: 280
- Joined: Thu Nov 28, 2013 9:32 am
- Location: Hamburg/Germany
- Contact:
Re: Load xml file "weak"-schema-aware
Hi Alex,
thanks for the code. It works nicely for the common validation errors (missing elements, dublicate ids).
But a failed xinclude still aborts loading the file. Is there maybe a way to keep the xincludes from being resolved at all? I could easily do this in my own java code.
BTW: The class ParserCreator is not listed in the javadoc. Is this on purpose or accidentally?
Thanks and Regards,
Patrik
thanks for the code. It works nicely for the common validation errors (missing elements, dublicate ids).
But a failed xinclude still aborts loading the file. Is there maybe a way to keep the xincludes from being resolved at all? I could easily do this in my own java code.
BTW: The class ParserCreator is not listed in the javadoc. Is this on purpose or accidentally?
Thanks and Regards,
Patrik
-
- Posts: 1016
- Joined: Wed Nov 16, 2005 11:11 am
Re: Load xml file "weak"-schema-aware
Post by alex_jitianu »
Hi Patrik,
If not expanding external entities is also a desired effect you can do it like this:
Otherwise, you can disable just XInclude processing by setting this option before creating the document builder:
Just don't forget to set it back to true afterwards.
Best regards,
Alex
If not expanding external entities is also a desired effect you can do it like this:
Code: Select all
boolean fakeResolver = false;
boolean noExpand = true;
boolean namespaceAware = true;
URL schemaUrl = null;
boolean schemaAware = true;
boolean forceXIncludeAndBaseURIFixup = false;
boolean dynamicValidation = true;
parserCreator.newDocumentBuilder(fakeResolver, noExpand, namespaceAware, schemaUrl, schemaAware, forceXIncludeAndBaseURIFixup, dynamicValidation);
Initially we didn't considered ParserCreator to be API per se.But as the need for it has risen we let it in the public code. Starting with 17.0 it will also be present in the Javadoc.
Code: Select all
Options.getInstance().setBooleanProperty("validation.xinclude", false)
Best regards,
Alex
-
- Posts: 280
- Joined: Thu Nov 28, 2013 9:32 am
- Location: Hamburg/Germany
- Contact:
Re: Load xml file "weak"-schema-aware
Thanks for the documentation. It worked but I realized that I need the to resolve the xincludes. However, adding an empty fallback in all xincludes is a sufficient alternative.
Regards,
Patrik
Regards,
Patrik
Return to “SDK-API, Frameworks - Document Types”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service