You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Somsak AsSawakulpaibool <so...@comhill.com> on 2001/02/28 22:39:36 UTC

Xalan2 with Xerces1.3

Hi guys,

I'm testing Xalan2 (xalan-j 2.0.0) with Xerces 1.3.0
I tested the schema validation by modified the DOM2DOM sample's code and create birds.xsd (see below codes).
It works fine with Xerces 1.2.3 (The one that comes with Xalan2), but I got below error when I run program.

What did I do wrong?

A.Somsak


-- ERROR MESSAGE --

Exception in thread "main" javax.xml.transform.TransformerException: DOM006 Hierarchy request error
        at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1212)
        at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:479)
        at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1118)
        at DOM2DOM.main(DOM2DOM.java:132)
---------
org.w3c.dom.DOMException: DOM006 Hierarchy request error
        at org.apache.xerces.dom.ParentNode.internalInsertBefore(ParentNode.java:394)
        at org.apache.xerces.dom.ParentNode.insertBefore(ParentNode.java:322)
        at org.apache.xerces.dom.DocumentImpl.insertBefore(DocumentImpl.java:356)
        at org.apache.xerces.dom.NodeImpl.appendChild(NodeImpl.java:216)
        at org.apache.xml.utils.DOMBuilder.append(DOMBuilder.java:172)
        at org.apache.xml.utils.DOMBuilder.characters(DOMBuilder.java:432)
        at org.apache.xalan.transformer.ResultTreeHandler.characters(ResultTreeHandler.java:446)
        at org.apache.xalan.templates.ElemForEach.transformSelectedNodes(ElemForEach.java:454)
        at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:193)
        at org.apache.xalan.templates.ElemForEach.transformSelectedNodes(ElemForEach.java:495)
        at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:193)
        at org.apache.xalan.templates.ElemForEach.transformSelectedNodes(ElemForEach.java:495)
        at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:193)
        at org.apache.xalan.templates.ElemForEach.transformSelectedNodes(ElemForEach.java:495)
        at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:193)
        at org.apache.xalan.templates.ElemForEach.transformSelectedNodes(ElemForEach.java:495)
        at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:193)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2154)
        at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2097)
        at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2029)
        at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1189)
        at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:479)
        at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1118)
        at DOM2DOM.main(DOM2DOM.java:132)

-----------------------------------------------------------------------------

-- DOM2DOM.java --

// Imported TraX classes
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.dom.DOMResult;

// Imported java.io classes
import java.io.IOException;
import java.io.FileNotFoundException;

// Imported SAX classes
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

// Imported DOM classes
import org.w3c.dom.Document;
import org.w3c.dom.Node;

// Imported Serializer classes
import org.apache.xalan.serialize.Serializer;
import org.apache.xalan.serialize.SerializerFactory;

import org.apache.xalan.templates.OutputProperties;

// Imported JAVA API for XML Parsing classes
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

  /**
   * Show how to transform a DOM tree into another DOM tree.
   * This uses the javax.xml.parsers to parse an XML file into a
   * DOM, and create an output DOM.
   */
public class DOM2DOM
{
	public static void main(String[] args)
    throws TransformerException, TransformerConfigurationException, FileNotFoundException,
           ParserConfigurationException, SAXException, IOException
  {
	  TransformerFactory tFactory = TransformerFactory.newInstance();

    if(tFactory.getFeature(DOMSource.FEATURE) && tFactory.getFeature(DOMResult.FEATURE))
    {
      // Process the stylesheet StreamSource and generate a Transformer.
      Transformer transformer = tFactory.newTransformer(new StreamSource("birds.xsl"));

      //Instantiate a DocumentBuilderFactory.
      DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
      
/********* I added the following 2 lines *************/ 
      dFactory.setValidating(true);
      dFactory.setNamespaceAware(true);
/*****************************************************/ 

      //Use the DocumentBuilderFactory to create a DocumentBuilder.
      DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
      

      //Use the DocumentBuilder to parse the XML input.
      Document doc = dBuilder.parse("birds.xml");

      // Use the DOM Document to define a DOMSource object.
      DOMSource domSource = new DOMSource(doc);

      // Set the base URI for the DOMSource so any relative URIs it contains can
      // be resolved.
      //domSource.setSystemId("birds.xml");

      // Create an empty DOMResult for the Result.
      DOMResult domResult = new DOMResult();

  	  // Perform the transformation, placing the output in the DOMResult.
      transformer.transform(domSource, domResult);

	    //Instantiate an XML serializer and use it to serialize the output DOM to System.out
	    // using a default output format.
      Serializer serializer = SerializerFactory.getSerializer
                                   (OutputProperties.getDefaultMethodProperties("xml"));
      serializer.setOutputStream(System.out);
      serializer.asDOMSerializer().serialize(domResult.getNode());
	}
    else
    {
      throw new org.xml.sax.SAXNotSupportedException("DOM node processing not supported!");
    }
  }
}


-----------------------------------------------------------------------------

-- BIRDS.XSD --
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" elementFormDefault="qualified">
	<xsd:element name="Class">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element ref="Order" maxOccurs="unbounded"/>
			</xsd:sequence>
		</xsd:complexType>
	</xsd:element>
	<xsd:element name="Family">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element ref="Species" maxOccurs="unbounded"/>
			</xsd:sequence>
			<xsd:attribute name="Name" type="xsd:string"/>
		</xsd:complexType>
	</xsd:element>
	<xsd:element name="Order">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element ref="Family" maxOccurs="unbounded"/>
			</xsd:sequence>
			<xsd:attribute name="Name" type="xsd:string"/>
		</xsd:complexType>
	</xsd:element>
	<xsd:element name="Species">
		<xsd:complexType  mixed="true">
			<xsd:attribute name="Scientific_Name" type="xsd:string"/>
		</xsd:complexType>
	</xsd:element>
</xsd:schema>

-----------------------------------------------------------------------------

-- BIRDS.XML --
<?xml version="1.0" encoding="UTF-8"?>
<Class xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:noNamespaceSchemaLocation="birds.xsd">
	<Order Name="TINAMIFORMES">
		<Family Name="TINAMIDAE">
			<Species Scientific_Name="Tinamus major"> Great Tinamou.</Species>
			<Species Scientific_Name="Nothocercus">Highland Tinamou.</Species>
			<Species Scientific_Name="Crypturellus soui">Little Tinamou.</Species>
			<Species Scientific_Name="Crypturellus cinnamomeus">Thicket Tinamou.</Species>
			<Species Scientific_Name="Crypturellus boucardi">Slaty-breasted Tinamou.</Species>
			<Species Scientific_Name="Crypturellus kerriae">Choco Tinamou.</Species>
		</Family>
	</Order>
	<Order Name="GAVIIFORMES">
		<Family Name="GAVIIDAE">
			<Species Scientific_Name="Gavia stellata">Red-throated Loon.</Species>
			<Species Scientific_Name="Gavia arctica">Arctic Loon.</Species>
			<Species Scientific_Name="Gavia pacifica">Pacific Loon.</Species>
			<Species Scientific_Name="Gavia immer">Common Loon.</Species>
			<Species Scientific_Name="Gavia adamsii">Yellow-billed Loon.</Species>
		</Family>
	</Order>
	<Order Name="PODICIPEDIFORMES">
		<Family Name="PODICIPEDIDAE">
			<Species Scientific_Name="Tachybaptus dominicus">Least Grebe.</Species>
			<Species Scientific_Name="Podilymbus podiceps">Pied-billed Grebe.</Species>
			<Species Scientific_Name="">Atitlan Grebe.</Species>
			<Species Scientific_Name="">Horned Grebe.</Species>
			<Species Scientific_Name="">Red-necked Grebe.</Species>
			<Species Scientific_Name="">Eared Grebe.</Species>
			<Species Scientific_Name="">Western Grebe.</Species>
			<Species Scientific_Name="">Clark's Grebe.</Species>
			<Species Scientific_Name=""/>
		</Family>
	</Order>
	<Order Name="PROCELLARIIFORMES">
		<Family Name="DIOMEDEIDAE">
			<Species Scientific_Name="Thalassarche chlororhynchos">Yellow-nosed Albatross. (A)</Species>
			<Species Scientific_Name="Thalassarche cauta">Shy Albatross. (A)</Species>
			<Species Scientific_Name="Thalassarche melanophris">Black-browed Albatross. (A)</Species>
			<Species Scientific_Name="Phoebetria palpebrata">Light-mantled Albatross. (A)</Species>
			<Species Scientific_Name="Diomedea exulans">Wandering Albatross. (A)</Species>
			<Species Scientific_Name="Phoebastria immutabilis">Laysan Albatross.</Species>
			<Species Scientific_Name="Phoebastria nigripes">Black-footed Albatross.</Species>
			<Species Scientific_Name="Phoebastria albatrus">Short-tailed Albatross. (N)</Species>
		</Family>
		<Family Name="PROCELLARIIDAE">
			<Species Scientific_Name="Fulmarus glacialis">Northern Fulmar.</Species>
			<Species Scientific_Name="Pterodroma neglecta">Kermadec Petrel. (A)</Species>
			<Species Scientific_Name="Pterodroma arminjoniana">Herald Petrel. (A)</Species>
			<Species Scientific_Name="Pterodroma ultima">Murphy's Petrel. (N)</Species>
			<Species Scientific_Name="Pterodroma inexpectata">Mottled Petrel. (A)</Species>
			<Species Scientific_Name="Pterodroma cahow">Bermuda Petrel.</Species>
			<Species Scientific_Name="Pterodroma hasitata">Black-capped Petrel.</Species>
			<Species Scientific_Name="Pterodroma externa">Juan Fernandez Petrel. (N)</Species>
			<Species Scientific_Name="Pterodroma phaeopygia">Dark-rumped Petrel.</Species>
			<Species Scientific_Name="Pterodroma cervicalis">White-necked Petrel. (H)</Species>
			<Species Scientific_Name="Pterodroma hypoleuca">Bonin Petrel. (H)</Species>
			<Species Scientific_Name="Pterodroma nigripennis">Black-winged Petrel. (H, A)</Species>
			<Species Scientific_Name="Pterodroma cookii">Cook's Petrel. (N)</Species>
			<Species Scientific_Name="Pterodroma longirostris">Stejneger's Petrel. (A)</Species>
			<Species Scientific_Name="Bulweria bulwerii">Bulwer's Petrel. (H)</Species>
			<Species Scientific_Name="Bulweria fallax">Jouanin's Petrel. (H, A)</Species>
			<Species Scientific_Name="Procellaria parkinsoni">Parkinson's Petrel. (N)</Species>
			<Species Scientific_Name="Calonectris leucomelas">Streaked Shearwater. (A)</Species>
			<Species Scientific_Name="Calonectris diomedea">Cory's Shearwater. (N)</Species>
			<Species Scientific_Name="Puffinus creatopus">Pink-footed Shearwater. (N)</Species>
			<Species Scientific_Name="Puffinus carneipes">Flesh-footed Shearwater. (N)</Species>
			<Species Scientific_Name="Puffinus gravis">Greater Shearwater. (N)</Species>
			<Species Scientific_Name="Puffinus pacificus">Wedge-tailed Shearwater.</Species>
			<Species Scientific_Name="Puffinus bulleri">Buller's Shearwater. (N)</Species>
			<Species Scientific_Name="Puffinus griseus">Sooty Shearwater. (N)</Species>
			<Species Scientific_Name="Puffinus tenuirostris">Short-tailed Shearwater. (N)</Species>
			<Species Scientific_Name="Puffinus nativitatis">Christmas Shearwater. (H)</Species>
			<Species Scientific_Name="Puffinus puffinus">Manx Shearwater.</Species>
			<Species Scientific_Name="Puffinus auricularis">Townsend's Shearwater.</Species>
			<Species Scientific_Name="Puffinus opisthomelas">Black-vented Shearwater.</Species>
			<Species Scientific_Name="Puffinus lherminieri">Audubon's Shearwater.</Species>
			<Species Scientific_Name="Puffinus assimilis">Little Shearwater. (A)</Species>
		</Family>
		<Family Name="HYDROBATIDAE">
			<Species Scientific_Name="Oceanites oceanicus">Wilson's Storm-Petrel. (N)</Species>
			<Species Scientific_Name="Pelagodroma marina">White-faced Storm-Petrel. (A)</Species>
			<Species Scientific_Name="Hydrobates pelagicus">European Storm-Petrel. (A)</Species>
			<Species Scientific_Name="Oceanodroma furcata">Fork-tailed Storm-Petrel.</Species>
			<Species Scientific_Name="Oceanodroma leucorhoa">Leach's Storm-Petrel.</Species>
			<Species Scientific_Name="Oceanodroma homochroa">Ashy Storm-Petrel.</Species>
			<Species Scientific_Name="Oceanodroma castro">Band-rumped Storm-Petrel. (N)</Species>
			<Species Scientific_Name="Oceanodroma tethys">Wedge-rumped Storm-Petrel. (N)</Species>
			<Species Scientific_Name="Oceanodroma melania">Black Storm-Petrel.</Species>
			<Species Scientific_Name="Oceanodroma macrodactyla">Guadalupe Storm-Petrel.</Species>
			<Species Scientific_Name="Oceanodroma markhami">Markham's Storm-Petrel. (A)</Species>
			<Species Scientific_Name="Oceanodroma tristrami">Tristram's Storm-Petrel. (H)</Species>
			<Species Scientific_Name="Oceanodroma microsoma">Least Storm-Petrel.</Species>
		</Family>
	</Order>
	<Order Name="PELECANIFORMES">
		<Family Name="PHAETHONTIDAE">
			<Species Scientific_Name="Phaethon lepturus">White-tailed Tropicbird.</Species>
			<Species Scientific_Name="Phaethon aethereus">Red-billed Tropicbird.</Species>
			<Species Scientific_Name="Phaethon rubricauda">Red-tailed Tropicbird.</Species>
		</Family>
		<Family Name="SULIDAE">
			<Species Scientific_Name="Sula dactylatra">Masked Booby.</Species>
			<Species Scientific_Name="Sula nebouxii">Blue-footed Booby.</Species>
			<Species Scientific_Name="Sula variegata">Peruvian Booby. (A)</Species>
			<Species Scientific_Name="Sula leucogaster">Brown Booby.</Species>
			<Species Scientific_Name="Sula sula">Red-footed Booby.</Species>
			<Species Scientific_Name="Morus bassanus">Northern Gannet.</Species>
		</Family>
		<Family Name="PELECANIDAE">
			<Species Scientific_Name="Pelecanus erythrorhynchos">American White Pelican.</Species>
			<Species Scientific_Name="Pelecanus occidentalis">Brown Pelican.</Species>
		</Family>
		<Family Name="PHALACROCORACIDAE">
			<Species Scientific_Name="Phalacrocorax penicillatus">Brandt's Cormorant.</Species>
			<Species Scientific_Name="Phalacrocorax brasilianus">Neotropic Cormorant.</Species>
			<Species Scientific_Name="Phalacrocorax auritus">Double-crested Cormorant.</Species>
			<Species Scientific_Name="Phalacrocorax carbo">Great Cormorant.</Species>
			<Species Scientific_Name="Phalacrocorax urile">Red-faced Cormorant.</Species>
			<Species Scientific_Name="Phalacrocorax pelagicus">Pelagic Cormorant.</Species>
		</Family>
		<Family Name="ANHINGIDAE">
			<Species Scientific_Name="Anhinga anhinga">Anhinga.</Species>
		</Family>
		<Family Name="FREGATIDAE">
			<Species Scientific_Name="Fregata magnificens">Magnificent Frigatebird.</Species>
			<Species Scientific_Name="Fregata minor">Great Frigatebird.</Species>
			<Species Scientific_Name="Fregata ariel">Lesser Frigatebird. (A)</Species>
		</Family>
	</Order>
</Class>

Re: Xalan2 with Xerces1.3

Posted by Gary L Peskin <ga...@firstech.com>.
Somsak AsSawakulpaibool wrote:
> 
> Hi guys,
> 
> I'm testing Xalan2 (xalan-j 2.0.0) with Xerces 1.3.0
> I tested the schema validation by modified the DOM2DOM sample's code and create birds.xsd (see below codes).
> It works fine with Xerces 1.2.3 (The one that comes with Xalan2), but I got below error when I run program.
> 
> What did I do wrong?
> 
> A.Somsak
> 
> -- ERROR MESSAGE --
> 
> Exception in thread "main" javax.xml.transform.TransformerException: DOM006 Hierarchy request error
> ...

This is caused by a mismatch in the template namespace (which is null)
and the Class element namespace (which is "").  Apparently Xerces now
correctly reports an empty string for the default namespace.  Somewhere
in our stylesheet ContentHandler, we must be changing it to a null. 
I'll look into where we can fix it most easily and make or post a
change.

Thank you for reporting this problem.

Gary

Re: Xalan2 with Xerces1.3

Posted by Gary L Peskin <ga...@firstech.com>.
Somsak AsSawakulpaibool wrote:
> 
> Hi guys,
> 
> I'm testing Xalan2 (xalan-j 2.0.0) with Xerces 1.3.0
> I tested the schema validation by modified the DOM2DOM sample's code and create birds.xsd (see below codes).
> It works fine with Xerces 1.2.3 (The one that comes with Xalan2), but I got below error when I run program.
> 
> What did I do wrong?
> 
> A.Somsak
> 
> -- ERROR MESSAGE --
> 
> Exception in thread "main" javax.xml.transform.TransformerException: DOM006 Hierarchy request error
> ...

This is caused by a mismatch in the template namespace (which is null)
and the Class element namespace (which is "").  Apparently Xerces now
correctly reports an empty string for the default namespace.  Somewhere
in our stylesheet ContentHandler, we must be changing it to a null. 
I'll look into where we can fix it most easily and make or post a
change.

Thank you for reporting this problem.

Gary