Unsupported node type in DOM!

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

Unsupported node type in DOM!

CANDAT, Jerome (INFOTEL)

Hello,

I've a problem when executing a request on a Document object I've created using Xerces :

Exception in thread "main" java.lang.IllegalArgumentException: Unsupported node type in DOM! 5 instance [mdash: null]
        at net.sf.saxon.dom.NodeWrapper.makeWrapper(Unknown Source)
        at net.sf.saxon.dom.NodeWrapper$ChildEnumeration.evaluateCurrentNode(Unknown Source)
        at net.sf.saxon.dom.NodeWrapper$ChildEnumeration.next(Unknown Source)
        at net.sf.saxon.om.Navigator$DescendantEnumeration.advance(Unknown Source)
        at net.sf.saxon.om.Navigator$DescendantEnumeration.advance(Unknown Source)
        at net.sf.saxon.om.Navigator$BaseEnumeration.next(Unknown Source)
        at net.sf.saxon.om.Navigator$DescendantEnumeration.advance(Unknown Source)
        at net.sf.saxon.om.Navigator$BaseEnumeration.next(Unknown Source)
        at net.sf.saxon.om.Navigator$DescendantEnumeration.advance(Unknown Source)
        at net.sf.saxon.om.Navigator$BaseEnumeration.next(Unknown Source)
        at net.sf.saxon.om.Navigator$AxisFilter.next(Unknown Source)
        at net.sf.saxon.expr.MappingIterator.next(Unknown Source)
        at net.sf.saxon.query.XQueryExpression$ErrorReportingIterator.next(Unknown Source)
        at net.sf.saxon.query.XQueryExpression.evaluate(Unknown Source)
        at Test.main(Test.java:119)

Here is my code :

System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
        "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");

    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
        .newInstance();

   documentBuilderFactory.setAttribute(
        "http://apache.org/xml/features/dom/create-entity-ref-nodes",
        Boolean.TRUE);
 
    DocumentBuilder documentBuilder = null;
    try {
      documentBuilder = documentBuilderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
      e.printStackTrace();
      System.err.println("ERROR occured while creating documentBuilder");
    }
    Document document = null;
    try {
      document = documentBuilder.parse(args[0]);
    } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
   
//  Initialize XQuery engine
    Configuration iConfiguration = new Configuration();
    iConfiguration.setHostLanguage(Configuration.XQUERY);
   
    Source iSource = new DOMSource(document);
    StaticQueryContext iStaticContext = new StaticQueryContext(iConfiguration);
    DynamicQueryContext iDynContext = new DynamicQueryContext(iConfiguration);
    DocumentInfo iDocInfo = null;
    try {
      iDocInfo = iStaticContext.buildDocument(iSource);
      iDynContext.setContextNode(iDocInfo.getRoot());
    }
    catch (net.sf.saxon.trans.XPathException ex) {
      ex.printStackTrace();
      }

    // First of all, get document revisions
    List iTitles = null;
    try {
      XQueryExpression iQuery = iStaticContext.compileQuery("//TITLE");
      iTitles = iQuery.evaluate(iDynContext);
    }
    catch (net.sf.saxon.trans.XPathException ex) {
      ex.printStackTrace();
    }

And the XML I'm working on :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE description [ <!ENTITY % ops.ent SYSTEM "characters.ent"> %ops.ent;]>
<ROOT>

   <TITLE>COMMENTS &mdash; QUESTIONS</TITLE>

</ROOT>

The file characters.ent contains entities declarations like <!ENTITY mdash "&amp;mdash;">

I cannot change the data as they are given to me as it is and have no means to make them change...


I saw the thread posted on June concerning the same problem so I know what causes the error but I was wondering if and how I could modify SAXON (maybe modify the 'makeWrapper' method) not to have this error so that ENTITY_REFERENCE nodes are simply discarded and do not generate an error?

Thanks in advance,
Jérôme.


This e-mail is intended only for the above addressee. It may contain
privileged information. If you are not the addressee you must not copy,
distribute, disclose or use any of the information in it. If you have
received it in error please delete it and immediately notify the sender.
Security Notice: all e-mail, sent to or from this address, may be
accessed by someone other than the recipient, for system management and
security reasons. This access is controlled under Regulation of
Investigatory Powers Act 2000, Lawful Business Practises.


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Unsupported node type in DOM!

Michael Kay
Node type 5 is an "entity reference node". Saxon can't handle a DOM
containing entity reference nodes, all the entities must have been fully
expanded.

The entity reference nodes are there because you have set:

>    documentBuilderFactory.setAttribute(
>         "http://apache.org/xml/features/dom/create-entity-ref-nodes",
>         Boolean.TRUE);

Do you really need them for your processing?

Michael Kay
Saxonica



> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> CANDAT, Jerome (INFOTEL)
> Sent: 18 October 2005 16:30
> To: [hidden email]
> Subject: [saxon] Unsupported node type in DOM!
>
>
> Hello,
>
> I've a problem when executing a request on a Document object
> I've created using Xerces :
>
> Exception in thread "main"
> java.lang.IllegalArgumentException: Unsupported node type in
> DOM! 5 instance [mdash: null]
> at net.sf.saxon.dom.NodeWrapper.makeWrapper(Unknown Source)
> at
> net.sf.saxon.dom.NodeWrapper$ChildEnumeration.evaluateCurrentN
> ode(Unknown Source)
> at
> net.sf.saxon.dom.NodeWrapper$ChildEnumeration.next(Unknown Source)
> at
> net.sf.saxon.om.Navigator$DescendantEnumeration.advance(Unknow
> n Source)
> at
> net.sf.saxon.om.Navigator$DescendantEnumeration.advance(Unknow
> n Source)
> at
> net.sf.saxon.om.Navigator$BaseEnumeration.next(Unknown Source)
> at
> net.sf.saxon.om.Navigator$DescendantEnumeration.advance(Unknow
> n Source)
> at
> net.sf.saxon.om.Navigator$BaseEnumeration.next(Unknown Source)
> at
> net.sf.saxon.om.Navigator$DescendantEnumeration.advance(Unknow
> n Source)
> at
> net.sf.saxon.om.Navigator$BaseEnumeration.next(Unknown Source)
> at net.sf.saxon.om.Navigator$AxisFilter.next(Unknown Source)
> at net.sf.saxon.expr.MappingIterator.next(Unknown Source)
> at
> net.sf.saxon.query.XQueryExpression$ErrorReportingIterator.nex
> t(Unknown Source)
> at net.sf.saxon.query.XQueryExpression.evaluate(Unknown Source)
> at Test.main(Test.java:119)
>
> Here is my code :
>
> System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
>         "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
>
>     DocumentBuilderFactory documentBuilderFactory =
> DocumentBuilderFactory
>         .newInstance();
>
>    documentBuilderFactory.setAttribute(
>         "http://apache.org/xml/features/dom/create-entity-ref-nodes",
>         Boolean.TRUE);
>  
>
>     DocumentBuilder documentBuilder = null;
>     try {
>       documentBuilder = documentBuilderFactory.newDocumentBuilder();
>     } catch (ParserConfigurationException e) {
>       e.printStackTrace();
>       System.err.println("ERROR occured while creating
> documentBuilder");
>     }
>     Document document = null;
>     try {
>       document = documentBuilder.parse(args[0]);
>     } catch (SAXException e) {
>       // TODO Auto-generated catch block
>       e.printStackTrace();
>     } catch (IOException e) {
>       // TODO Auto-generated catch block
>       e.printStackTrace();
>     }
>    
>
> //  Initialize XQuery engine
>     Configuration iConfiguration = new Configuration();
>     iConfiguration.setHostLanguage(Configuration.XQUERY);
>    
>
>     Source iSource = new DOMSource(document);
>     StaticQueryContext iStaticContext = new
> StaticQueryContext(iConfiguration);
>     DynamicQueryContext iDynContext = new
> DynamicQueryContext(iConfiguration);
>     DocumentInfo iDocInfo = null;
>     try {
>       iDocInfo = iStaticContext.buildDocument(iSource);
>       iDynContext.setContextNode(iDocInfo.getRoot());
>     }
>     catch (net.sf.saxon.trans.XPathException ex) {
>       ex.printStackTrace();
>       }
>
>     // First of all, get document revisions
>     List iTitles = null;
>     try {
>       XQueryExpression iQuery =
> iStaticContext.compileQuery("//TITLE");
>       iTitles = iQuery.evaluate(iDynContext);
>     }
>     catch (net.sf.saxon.trans.XPathException ex) {
>       ex.printStackTrace();
>     }
>
> And the XML I'm working on :
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE description [ <!ENTITY % ops.ent SYSTEM
> "characters.ent"> %ops.ent;]>
> <ROOT>
>
>
>    <TITLE>COMMENTS &mdash; QUESTIONS</TITLE>
>
>
> </ROOT>
>
> The file characters.ent contains entities declarations like
> <!ENTITY mdash "&amp;mdash;">
>
> I cannot change the data as they are given to me as it is and
> have no means to make them change...
>
>
> I saw the thread posted on June concerning the same problem
> so I know what causes the error but I was wondering if and
> how I could modify SAXON (maybe modify the 'makeWrapper'
> method) not to have this error so that ENTITY_REFERENCE nodes
> are simply discarded and do not generate an error?
>
>
> Thanks in advance,
> Jérôme.
>
>
>
> This e-mail is intended only for the above addressee. It may contain
> privileged information. If you are not the addressee you must
> not copy,
> distribute, disclose or use any of the information in it. If you have
> received it in error please delete it and immediately notify
> the sender.
> Security Notice: all e-mail, sent to or from this address, may be
> accessed by someone other than the recipient, for system
> management and
> security reasons. This access is controlled under Regulation of
> Investigatory Powers Act 2000, Lawful Business Practises.
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Power Architecture Resource Center: Free content, downloads,
> discussions,
> and more. http://solutions.newsforge.com/ibmarch.tmpl
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Unsupported node type in DOM!

CANDAT, Jerome (INFOTEL)
In reply to this post by CANDAT, Jerome (INFOTEL)

Hello,

Node type 5 is an "entity reference node". Saxon can't handle a DOM
containing entity reference nodes, all the entities must have been fully
expanded.

The entity reference nodes are there because you have set:

>    documentBuilderFactory.setAttribute(
>         "http://apache.org/xml/features/dom/create-entity-ref-nodes",
>         Boolean.TRUE);


Do you really need them for your processing?

--> I do need the entity references in my processing and want to make it in one shot. What I mean by this is that I can't parse my document once, do my processing with SAXON then serialize it again with the modifications and re-parse this serialized file (with entities references) to do another processing.

I have looked at the given stack trace and modified SAXON code ('makeWrapper' method in the net.sf.saxon.dom.NodeWrapper class) by adding the following lines :

case Node.ENTITY_REFERENCE_NODE:
          wrapper = new NodeWrapper(node, parent, index);
          wrapper.nodeKind = Type.COMMENT;
break;


It seems to work on my example but I was wondering if my modifications were valid or not and if any problem can occur whit this modification.

Thanks in advance,
Jérôme.


This e-mail is intended only for the above addressee. It may contain
privileged information. If you are not the addressee you must not copy,
distribute, disclose or use any of the information in it. If you have
received it in error please delete it and immediately notify the sender.
Security Notice: all e-mail, sent to or from this address, may be
accessed by someone other than the recipient, for system management and
security reasons. This access is controlled under Regulation of
Investigatory Powers Act 2000, Lawful Business Practises.


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: RE: Unsupported node type in DOM!

Michael Kay
> I have looked at the given stack trace and modified SAXON
> code ('makeWrapper' method in the
> net.sf.saxon.dom.NodeWrapper class) by adding the following lines :
>
> case Node.ENTITY_REFERENCE_NODE:
>           wrapper = new NodeWrapper(node, parent, index);
>           wrapper.nodeKind = Type.COMMENT;
> break;
>
>
> It seems to work on my example but I was wondering if my
> modifications were valid or not and if any problem can occur
> whit this modification.

The answer is that it will almost certainly break something, but I can't
tell exactly what without a considerable amount of testing. It will probably
break any stylesheet that accesses real comments, because a DOM entity
reference node has a null nodeValue, and the code for processing comments
assumes a non-null nodeValue.

It's very often the case with things like this that you need to create 50
test cases to determine whether a three-line source change is viable: and in
the case of DOM code, you need to run these tests against three different
DOM implementations before you can be sure it's OK.

At the very least, your change will create a data model that is an incorrect
representation of the source document: the text or element nodes that are
children of the entity reference will not be visible as part of the tree,
and will not be copied by an xsl:copy operation. So even if the patch works
for you, it's certainly not a general solution.

If this facility is sufficiently important to you that your company would be
interested in sponsoring the development of a solution, please contact me
off-list.

Michael Kay
http://www.saxonica.com/




-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help