You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Cory Isaacson (Compuflex)" <ci...@compuflex.com> on 2001/03/26 00:14:19 UTC
Possible XPathAPI Bug
I'm not sure if this is a bug in Xerces or Xalan. I am using Xalan 2.0, and
also tried the latest release (same behavior in both).
I built a DOM using Xerces from scratch (using new DocumentImpl()), and
assign a namespace to the root element (using createElementNS()). When I
serialize the DOM, it does not include the 'xmlns' attribute in the output.
If I transform the DOM with a regular stylesheet, it finds all nodes
perfectly, using the namespace prefix. However, if I use XPathAPI to find a
node, it doesn't see it.
I then started with a template XML file that included only the root node,
and the namespace attribute in the root node. I parsed it and then built the
DOM from there. When I serialize this DOM it does include the xmlns
attribute in the output, and both the stylesheet and the XPathAPI work fine.
Any ideas?
Thanks,
Cory
RE: Possible XPathAPI Bug
Posted by "Cory Isaacson (Compuflex)" <ci...@compuflex.com>.
Gary,
Below you can see the relevant snippets. I have included the example that
does not work. The one that does work is virtually the same, except instead
of creating a new DOM using 'new DocumentImpl()' we do it using the
DOMParser.parse command (using the skeleton document).
Thanks,
Cory
/* Build the DOM from scratch.*/
public void initNodeTree()
throws Exception
{
/* Outline:
*
* Create tree document instance.
* Retrieve dsHierarchyNetwork.
* Append network to document.
*/
/* Declare variables.*/
Element treeElement = null;
int rowCount = 0;
int i = 0;
String networkNo = null;
String networkName = null;
Element networkElement = null;
/* Create tree document instance.*/
nodeTreeDoc = new DocumentImpl();
/* Append the treeElement (document root).*/
treeElement = nodeTreeDoc.createElementNS(bjNamespace, "bj:tree");
nodeTreeDoc.appendChild(treeElement);
...get some record data
/* Append network to document.*/
for(i=1;i<=rowCount;i++)
{
/* Get the values.*/
...get the value for each column in the row
/* Create the elements and append to the doc.*/
networkElement = nodeTreeDoc.createElementNS(bjNamespace,
"bj:network");
networkElement.setAttribute("ID", networkName);
networkElement.setAttribute("networkNo", networkNo);
treeElement.appendChild(networkElement);
}//for(i=1;i<=rowCount;i++)
}
/**
* Expand the node tree one level.
* This uses XPathAPI to find the selected node, and then insert children
* under it.
*/
public void expandNodeTree(String parentType, String parentNo)
throws Exception
{
/* Declare variables.*/
...
/* Set the child dataSet based on parentType, and build the xpath.*/
...
xpath = "/bj:tree/bj:network[@networkNo='" + parentNo + "']";
/* Find the parent node in the document.*/
/* This fails if a namespace is used.*/
parentElement = (Element)XPathAPI.selectSingleNode(nodeTreeDoc, xpath);
if(parentElement == null)
{
throw new Exception("The parent node could not be found in the
nodeTreeDoc.");
}//if(parentElement == null)
...some other processing using the parent
}//public void expandNodeTree(String)
-----Original Message-----
From: Gary L Peskin [mailto:garyp@firstech.com]
Sent: Sunday, March 25, 2001 2:50 PM
To: xalan-dev@xml.apache.org
Subject: Re: Possible XPathAPI Bug
> "Cory Isaacson (Compuflex)" wrote:
>
> I'm not sure if this is a bug in Xerces or Xalan. I am using Xalan
> 2.0, and also tried the latest release (same behavior in both).
>
> I built a DOM using Xerces from scratch (using new DocumentImpl()),
> and assign a namespace to the root element (using createElementNS()).
> When I serialize the DOM, it does not include the 'xmlns' attribute in
> the output. If I transform the DOM with a regular stylesheet, it finds
> all nodes perfectly, using the namespace prefix. However, if I use
> XPathAPI to find a node, it doesn't see it.
>
> I then started with a template XML file that included only the root
> node, and the namespace attribute in the root node. I parsed it and
> then built the DOM from there. When I serialize this DOM it does
> include the xmlns attribute in the output, and both the stylesheet and
> the XPathAPI work fine.
>
> Any ideas?
>
> Thanks,
>
> Cory
Cory --
Can you supply your java code that creates the DOM and tries to do the
transform with XPathAPI so that we can try to recreate the problem?
Thanks,
Gary
Re: Possible XPathAPI Bug
Posted by Gary L Peskin <ga...@firstech.com>.
> "Cory Isaacson (Compuflex)" wrote:
>
> I'm not sure if this is a bug in Xerces or Xalan. I am using Xalan
> 2.0, and also tried the latest release (same behavior in both).
>
> I built a DOM using Xerces from scratch (using new DocumentImpl()),
> and assign a namespace to the root element (using createElementNS()).
> When I serialize the DOM, it does not include the 'xmlns' attribute in
> the output. If I transform the DOM with a regular stylesheet, it finds
> all nodes perfectly, using the namespace prefix. However, if I use
> XPathAPI to find a node, it doesn't see it.
>
> I then started with a template XML file that included only the root
> node, and the namespace attribute in the root node. I parsed it and
> then built the DOM from there. When I serialize this DOM it does
> include the xmlns attribute in the output, and both the stylesheet and
> the XPathAPI work fine.
>
> Any ideas?
>
> Thanks,
>
> Cory
Cory --
Can you supply your java code that creates the DOM and tries to do the
transform with XPathAPI so that we can try to recreate the problem?
Thanks,
Gary