Hi, Ajay.

ajay bhadauria <[EMAIL PROTECTED]> wrote on 2008-10-27 01:10:34 PM:
> I am using xalan jar files for xsl transformation. I am using my 
> custom class to call java method. It gives me below error if I add 
> another node within /Doc:Document/Doc:camt.028.001.02/Doc:Assgnmt . 
> Please see the attached file c.xml file 
> 
> SystemId Unknown; Line #0; Column #0; org.w3c.dom.DOMException: 
> HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it
> is not permitted.

I can't actually run your test, as I don't have your Validator class. 
However, I'm guessing that your stylesheet produces a result tree that 
consists of a root node with a non-whitespace text node child.

Your Java program contains the following.

    DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
    Document doc = dBuilder.newDocument();

    ...

    Source source = new DOMSource( document );
    Result result = new DOMResult( doc );
    System.out.println("debug1");
    xformer.transform( source,result);

So it's using a DOM Document node to contain the result.  Although the 
XPath data model and XSLT allow for trees where the root node has 
non-whitespace text node children, and more than one element child, DOM 
Document nodes permit only one Element node child and no non-whitespace 
Text node children.

To fix this, create either a DOM DocumentFragment node or a DOM Element 
node to contain the result tree, like this:

    DocumentFragment resultRoot = doc.createDocumentFragment();
    Result result = new DOMResult( resultRoot );

Or you can use the zero-argument DOMResult constructor, in which case the 
processor will create a DocumentFragment node for you, like this:


    Result result = new DOMResult();
    System.out.println("debug1");
    xformer.transform( source,result);
    Node resultRoot = result.getNode();

I hope that helps.

Thanks,

Henry
------------------------------------------------------------------
Henry Zongaro
XML Transformation & Query Development
IBM Toronto Lab   T/L 313-6044;  Phone +1 905 413-6044
mailto:[EMAIL PROTECTED]

Reply via email to