How to read XML using XMLPackageReader-Drools-compiler.5.2.1.final?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to read XML using XMLPackageReader-Drools-compiler.5.2.1.final?

Praveen
Hi,

I am using Drools-compiler.5.2.1.final.
I am trying to convert an drl to xml and vice versa using DrlParser, DrlDumper, XMLPackageReader and XML Dumper.
Drl to XML conversion works fine but XML to Drl throws NPE.
I have placed the XML file under a folder called sample.
NPE is thrown at line 5..
Also attached is the exception.
Please suggest.
TIA.

Reader source = new InputStreamReader(
                    DroolsConversionHelper.class.getResourceAsStream(xmlFileName));
                 
                  PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
                        XmlPackageReader reader = new XmlPackageReader(conf.getSemanticModules());
                        DrlDumper dumper = new DrlDumper();
        //line 5 reader.read(source);
                        PackageDescr descr = reader.getPackageDescr();
                        String test = dumper.dump(descr);
                        System.out.println(test);



java.lang.NullPointerException
        at org.drools.xml.ExtensibleXmlParser.resolveSchema(ExtensibleXmlParser.java:696)
        at org.drools.xml.ExtensibleXmlParser.resolveEntity(ExtensibleXmlParser.java:622)
        at com.sun.org.apache.xerces.internal.util.EntityResolverWrapper.resolveEntity(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.resolveEntity(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.resolveDocument(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)



Regards,
Praveen.
Reply | Threaded
Open this post in threaded view
|

Re: How to read XML using XMLPackageReader-Drools-compiler.5.2.1.final?

abhinay_agarwal
This post was updated on .
Though the post is very old, it may help someone to know the solution.

This works well with 5.x. Tested with 5.6.0 ! :)

     public static void XMLtoDRL() {
                try {
                        PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
                        final XmlPackageReader xmlPackageReader = new XmlPackageReader(
                                        conf.getSemanticModules());
                        xmlPackageReader.read(new InputStreamReader(XMLtoDRLConverter.class
                                        .getResourceAsStream("Sample.xml")));
                        final PackageDescr pkg = xmlPackageReader.getPackageDescr();
                        final DrlDumper drlDumper = new DrlDumper();
                        final String drlResult = drlDumper.dump(pkg);
                        System.out.println(drlResult);
                } catch (SAXException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }