Hi Brock,

Maybe you have xerces installed as bundle in your distribution ?

It sounds like a version mismatch.

Can you share the bundles installed ?

Thanks,
Regards
JB

> Le 23 févr. 2021 à 16:55, brock samson <brock.sams...@hotmail.com> a écrit :
> 
> Hello, 
>  
> I am using Karaf 4.2.10 and attempting to perform a rather simple xml 
> parsing: 
>  
> Caused by: java.lang.NullPointerException 
>                 at org.apache.xerces.util.ErrorHandlerProxy.error(Unknown 
> Source) ~[!/:?] 
>                 at 
> com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:137)
>  ~[?:1.8.0_102] 
>                 at 
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396)
>  ~[?:1.8.0_102] 
>                 at 
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
>  ~[?:1.8.0_102] 
>                 at 
> com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284)
>  ~[?:1.8.0_102] 
>                 at 
> com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1900)
>  ~[?:1.8.0_102] 
>                 at 
> com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:740)
>  ~[?:1.8.0_102] 
>                 at 
> com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(ValidatorHandlerImpl.java:570)
>  ~[?:1.8.0_102] 
>                 at 
> org.apache.xerces.jaxp.JAXPValidatorComponent$XNI2SAX.startElement(Unknown 
> Source) ~[!/:?] 
>                 at 
> org.apache.xerces.jaxp.JAXPValidatorComponent.startElement(Unknown Source) 
> ~[!/:?] 
>                 at 
> org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown 
> Source) ~[!/:?] 
>                 at 
> org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown
>  Source) ~[!/:?] 
>                 at 
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
>  Source) ~[!/:?] 
>                 at 
> org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown 
> Source) ~[!/:?] 
>                 at org.apache.xerces.parsers.XML11Configuration.parse(Unknown 
> Source) ~[!/:?] 
>                 at org.apache.xerces.parsers.XML11Configuration.parse(Unknown 
> Source) ~[!/:?] 
>                 at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) 
> ~[!/:?] 
>                 at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) 
> ~[!/:?] 
>                 at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown 
> Source) ~[!/:?] 
>                 at 
> javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121) 
> ~[?:1.8.0_102] 
>  
> After snooping around, I noticed a 
> /container/lib/endorsed/org.apache.karaf.specs.java.xml-4.2.10.jar lib 
> containing parser-related libs. My code executed successfully once I ran 
> Karaf without this particular file, though I don’t feel right just pulling it 
> out of Karaf blindly, as its absence creates a distinct possibility of 
> unforeseen issues down the road. 
>  
> Here are the only imports my bundle references in its manifest: 
> Import-Package: 
> javax.xml.transform,javax.xml.transform.stream,org.xml.sax,javax.xml.parsers,javax.xml.validation
>  
> There are no entries under Bundle-Classpath 
>  
> Lastly, here is the java code that performs the xml parsing: 
>  
>             DocumentBuilderFactory factory = 
> DocumentBuilderFactory.newInstance(); 
>             SchemaFactory sf = 
> SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 
>             Schema schema = sf.newSchema(new StreamSource(new 
> FileInputStream("<LOCATION-OF-THE-SCHEMA-FILE>"))); 
>             factory.setNamespaceAware(true); 
>             factory.setSchema(schema); 
>             factory.setExpandEntityReferences(false); 
>             factory.setXIncludeAware(false);             
>             
> factory.setFeature("http://xml.org/sax/features/external-parameter-entities 
> <http://xml.org/sax/features/external-parameter-entities>",false); 
>             
> factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd
>  <http://apache.org/xml/features/nonvalidating/load-external-dtd>",false); 
>             
> factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl 
> <http://apache.org/xml/features/disallow-doctype-decl>", true); 
>             
> factory.setFeature("http://xml.org/sax/features/external-general-entities 
> <http://xml.org/sax/features/external-general-entities>",false);             
>             DocumentBuilder builder = factory.newDocumentBuilder(); 
>             builder.setErrorHandler(null); 
>             byte[] fileContent = 
> Files.readAllBytes(Paths.get("<LOCATION-OF-THE-XML-FILE-TO-BE-PARSED>")); 
>             InputStream inStream = new ByteArrayInputStream(fileContent); 
> Document doc = builder.parse(inStream); 
>  
> Please advise me as to what I am doing wrong, as well as a possible solution. 
> Thank you for your time! 
>  
> Sincerely, 
>  
> Brock Samson

Reply via email to