|
View:
New views
8 Messages
—
Rating Filter:
Alert me
|
|
|
Problem evaluating XPath expression into a NodeListI have a class that evaluates an XPath expression against an XML stream
with multiple namespaces and returns a NodeList. I know by looking at the XML that the node I am retrieving is composed of 20 elements, called '<summary>'. I also know that two of those elements have no value. The relevant code looks like this: XML2Doc xmldoc = new XML2Doc(getXmlFile()); Document domTree = (Document) xmldoc.getDoc(); domTree.getDocumentElement().normalize(); NamespaceResolver myResolver = new NamespaceResolver(); XObject xObj = XPathAPI.eval(domTree,getXpathExp(),myResolver); NodeList = xObj.nodelist(); The problem I am running into is that of the 20 <summary> elements some are empty (<summary type="html"></summary>). Upon evaluating the XPath expression the NodeList returned only 18 items event though I know there are twenty. It seems that the elements that weren't valued became insignificant as the NodeList was generated. Is this the correct behavior? I'm expecting my NodeList to have the same number of <summary> elements because I'll be matching them against their related <title> elements during presentation time. Perhaps there is something I need to do in my code to establish the fact that empty elements are significant and should be included in the NodeList? I tried removing the normalize() call but that didn't help. To make things more interesting I am developing this code using JDK 1.4.2 because that it is the development environment the customer is using and requires. Thanks - Tod |
|
|
Re: Problem evaluating XPath expression into a NodeListInsufficient data. What does the input
document look like and what is your XPath?
______________________________________ "... Three things see no end: A loop with exit code done wrong, A semaphore untested, And the change that comes along. ..." -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish (http://www.ovff.org/pegasus/songs/threes-rev-11.html) Tod <listacctc@...> wrote on 10/21/2009 02:00:02 PM: > Tod <listacctc@...> > 10/21/2009 02:00 PM > > To > > xalan-j-users@... > > cc > > Subject > > Problem evaluating XPath expression into a NodeList > > I have a class that evaluates an XPath expression against an XML stream > with multiple namespaces and returns a NodeList. I know by looking at > the XML that the node I am retrieving is composed of 20 elements, called > '<summary>'. I also know that two of those elements have no value. The > relevant code looks like this: > > > XML2Doc xmldoc = new XML2Doc(getXmlFile()); > Document domTree = (Document) xmldoc.getDoc(); > domTree.getDocumentElement().normalize(); > NamespaceResolver myResolver = new NamespaceResolver(); > XObject xObj = XPathAPI.eval(domTree,getXpathExp(),myResolver); > NodeList = xObj.nodelist(); > > > > > > The problem I am running into is that of the 20 <summary> elements some > are empty (<summary type="html"></summary>). Upon evaluating the XPath > expression the NodeList returned only 18 items event though I know there > are twenty. It seems that the elements that weren't valued became > insignificant as the NodeList was generated. > > Is this the correct behavior? I'm expecting my NodeList to have the > same number of <summary> elements because I'll be matching them against > their related <title> elements during presentation time. Perhaps there > is something I need to do in my code to establish the fact that empty > elements are significant and should be included in the NodeList? I > tried removing the normalize() call but that didn't help. > > To make things more interesting I am developing this code using JDK > 1.4.2 because that it is the development environment the customer is > using and requires. > > > Thanks - Tod > |
|
|
Re: Problem evaluating XPath expression into a NodeListOn 10/21/2009 3:34 PM, keshlam@... wrote:
> Insufficient data. What does the input document look like and what is > your XPath? > > > Tod <listacctc@...> wrote on 10/21/2009 02:00:02 PM: > > > Tod <listacctc@...> > > 10/21/2009 02:00 PM > > > > To > > > > xalan-j-users@... > > > > cc > > > > Subject > > > > Problem evaluating XPath expression into a NodeList > > > > I have a class that evaluates an XPath expression against an XML stream > > with multiple namespaces and returns a NodeList. I know by looking at > > the XML that the node I am retrieving is composed of 20 elements, called > > '<summary>'. I also know that two of those elements have no value. The > > relevant code looks like this: > > > > > > XML2Doc xmldoc = new XML2Doc(getXmlFile()); > > Document domTree = (Document) xmldoc.getDoc(); > > domTree.getDocumentElement().normalize(); > > NamespaceResolver myResolver = new NamespaceResolver(); > > XObject xObj = XPathAPI.eval(domTree,getXpathExp(),myResolver); > > NodeList = xObj.nodelist(); > > > > > > > > > > > > The problem I am running into is that of the 20 <summary> elements some > > are empty (<summary type="html"></summary>). Upon evaluating the XPath > > expression the NodeList returned only 18 items event though I know there > > are twenty. It seems that the elements that weren't valued became > > insignificant as the NodeList was generated. > > > > Is this the correct behavior? I'm expecting my NodeList to have the > > same number of <summary> elements because I'll be matching them against > > their related <title> elements during presentation time. Perhaps there > > is something I need to do in my code to establish the fact that empty > > elements are significant and should be included in the NodeList? I > > tried removing the normalize() call but that didn't help. > > > > To make things more interesting I am developing this code using JDK > > 1.4.2 because that it is the development environment the customer is > > using and requires. > > > > > > Thanks - Tod > > AtomXML - http://tools.ietf.org/html/rfc4287, with a couple of extra namespace definitions thrown in. On page two of the RFC there is an example. To demonstrate the problem I'm running into just remove the string "Some text." from the example XML. You may be familiar with the XML document format as it is the format returned by the IBM Omnifind Yahoo! Edition enterprise search. My XPath expression is: /default:feed/default:entry/default:summary/text() Where 'default' is the AtomXML namespace "http://www.w3.org/2005/Atom". Thanks - Tod |
|
|
Re: Problem evaluating XPath expression into a NodeListIt seems that you are not asking for a list of summary nodes - but a
list of text nodes made by the text of each summary node. what happens if you use: /default:feed/default:entry/default:summary instead of /default:feed/default:entry/default:summary/text() /Christoffer On 22-10-2009 13:53, Tod wrote: > On 10/21/2009 3:34 PM, keshlam@... wrote: >> Insufficient data. What does the input document look like and what >> is your XPath? >> >> >> Tod <listacctc@...> wrote on 10/21/2009 02:00:02 PM: >> >> > Tod <listacctc@...> >> > 10/21/2009 02:00 PM >> > >> > To >> > >> > xalan-j-users@... >> > >> > cc >> > >> > Subject >> > >> > Problem evaluating XPath expression into a NodeList >> > >> > I have a class that evaluates an XPath expression against an XML >> stream >> > with multiple namespaces and returns a NodeList. I know by looking at >> > the XML that the node I am retrieving is composed of 20 elements, >> called >> > '<summary>'. I also know that two of those elements have no >> value. The >> > relevant code looks like this: >> > >> > >> > XML2Doc xmldoc = new XML2Doc(getXmlFile()); >> > Document domTree = (Document) xmldoc.getDoc(); >> > domTree.getDocumentElement().normalize(); >> > NamespaceResolver myResolver = new NamespaceResolver(); >> > XObject xObj = XPathAPI.eval(domTree,getXpathExp(),myResolver); >> > NodeList = xObj.nodelist(); >> > >> > >> > >> > >> > >> > The problem I am running into is that of the 20 <summary> elements >> some >> > are empty (<summary type="html"></summary>). Upon evaluating the >> XPath >> > expression the NodeList returned only 18 items event though I know >> there >> > are twenty. It seems that the elements that weren't valued became >> > insignificant as the NodeList was generated. >> > >> > Is this the correct behavior? I'm expecting my NodeList to have the >> > same number of <summary> elements because I'll be matching them >> against >> > their related <title> elements during presentation time. Perhaps >> there >> > is something I need to do in my code to establish the fact that empty >> > elements are significant and should be included in the NodeList? I >> > tried removing the normalize() call but that didn't help. >> > >> > To make things more interesting I am developing this code using JDK >> > 1.4.2 because that it is the development environment the customer is >> > using and requires. >> > >> > >> > Thanks - Tod >> > > > > > AtomXML - http://tools.ietf.org/html/rfc4287, with a couple of extra > namespace definitions thrown in. On page two of the RFC there is an > example. To demonstrate the problem I'm running into just remove the > string "Some text." from the example XML. > > You may be familiar with the XML document format as it is the format > returned by the IBM Omnifind Yahoo! Edition enterprise search. > > My XPath expression is: > > /default:feed/default:entry/default:summary/text() > > Where 'default' is the AtomXML namespace "http://www.w3.org/2005/Atom". > > > > Thanks - Tod |
|
|
Re: Problem evaluating XPath expression into a NodeListTod,
It seems that you want the 'summary' elements and not their content (as they may be empty). Drop the "/text()" from the end of your XPath expression. Hope this helps. -- Santiago On Oct 22, 2009, at 7:53 AM, Tod wrote: > On 10/21/2009 3:34 PM, keshlam@... wrote: >> Insufficient data. What does the input document look like and what >> is your XPath? >> Tod <listacctc@...> wrote on 10/21/2009 02:00:02 PM: >> > Tod <listacctc@...> >> > 10/21/2009 02:00 PM >> > >> > To >> > >> > xalan-j-users@... >> > >> > cc >> > >> > Subject >> > >> > Problem evaluating XPath expression into a NodeList >> > >> > I have a class that evaluates an XPath expression against an XML >> stream >> > with multiple namespaces and returns a NodeList. I know by >> looking at >> > the XML that the node I am retrieving is composed of 20 elements, >> called >> > '<summary>'. I also know that two of those elements have no >> value. The >> > relevant code looks like this: >> > >> > >> > XML2Doc xmldoc = new XML2Doc(getXmlFile()); >> > Document domTree = (Document) xmldoc.getDoc(); >> > domTree.getDocumentElement().normalize(); >> > NamespaceResolver myResolver = new NamespaceResolver(); >> > XObject xObj = XPathAPI.eval(domTree,getXpathExp(),myResolver); >> > NodeList = xObj.nodelist(); >> > >> > >> > >> > >> > >> > The problem I am running into is that of the 20 <summary> >> elements some >> > are empty (<summary type="html"></summary>). Upon evaluating the >> XPath >> > expression the NodeList returned only 18 items event though I >> know there >> > are twenty. It seems that the elements that weren't valued became >> > insignificant as the NodeList was generated. >> > >> > Is this the correct behavior? I'm expecting my NodeList to have >> the >> > same number of <summary> elements because I'll be matching them >> against >> > their related <title> elements during presentation time. Perhaps >> there >> > is something I need to do in my code to establish the fact that >> empty >> > elements are significant and should be included in the NodeList? I >> > tried removing the normalize() call but that didn't help. >> > >> > To make things more interesting I am developing this code using JDK >> > 1.4.2 because that it is the development environment the customer >> is >> > using and requires. >> > >> > >> > Thanks - Tod >> > > > > > AtomXML - http://tools.ietf.org/html/rfc4287, with a couple of extra > namespace definitions thrown in. On page two of the RFC there is an > example. To demonstrate the problem I'm running into just remove > the string "Some text." from the example XML. > > You may be familiar with the XML document format as it is the format > returned by the IBM Omnifind Yahoo! Edition enterprise search. > > My XPath expression is: > > /default:feed/default:entry/default:summary/text() > > Where 'default' is the AtomXML namespace "http://www.w3.org/2005/ > Atom". > > > > Thanks - Tod |
|
|
Re: Problem evaluating XPath expression into a NodeList> /default:feed/default:entry/default:summary/text()
You're asking for text nodes. In the XPath view of the document, there is no such thing as an empty text node, so the empty elements have no children and do not contribute to this result. If you want to see them, search for the elements and then ask each one for its text content as a separate operation. ______________________________________ "... Three things see no end: A loop with exit code done wrong, A semaphore untested, And the change that comes along. ..." -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish (http://www.ovff.org/pegasus/songs/threes-rev-11.html) |
|
|
Re: Problem evaluating XPath expression into a NodeListOn 10/22/2009 8:39 AM, keshlam@... wrote:
> > /default:feed/default:entry/default:summary/text() > > You're asking for text nodes. In the XPath view of the document, there > is no such thing as an empty text node, so the empty elements have no > children and do not contribute to this result. > > If you want to see them, search for the elements and then ask each one > for its text content as a separate operation. > > ______________________________________ > "... Three things see no end: A loop with exit code done wrong, > A semaphore untested, And the change that comes along. ..." > -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish ( > http://www.ovff.org/pegasus/songs/threes-rev-11.html > <http://www.ovff.org/pegasus/songs/threes-rev-11.html> ) Thanks all for your help. I am now iterating through the results returned by the XPath eval of '/default:feed/default:entry/default:summary'. Could anybody suggest an elegant way to get these individual node values back into a nodelist which my class is expected to return? Thanks again - Tod |
|
|
Re: Problem evaluating XPath expression into a NodeListOn 10/22/2009 3:07 PM, Tod wrote:
> On 10/22/2009 8:39 AM, keshlam@... wrote: >> > /default:feed/default:entry/default:summary/text() >> >> You're asking for text nodes. In the XPath view of the document, there >> is no such thing as an empty text node, so the empty elements have no >> children and do not contribute to this result. >> >> If you want to see them, search for the elements and then ask each one >> for its text content as a separate operation. >> >> ______________________________________ >> "... Three things see no end: A loop with exit code done wrong, >> A semaphore untested, And the change that comes along. ..." >> -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish ( >> http://www.ovff.org/pegasus/songs/threes-rev-11.html >> <http://www.ovff.org/pegasus/songs/threes-rev-11.html> ) > > > Thanks all for your help. I am now iterating through the results > returned by the XPath eval of > '/default:feed/default:entry/default:summary'. > > Could anybody suggest an elegant way to get these individual node values > back into a nodelist which my class is expected to return? > > Thanks again - Tod > Follow up... All I needed to do was to add a boolean to the XPath expression: /default:feed/default:entry/default:summary/text()|/default:feed/default:entry/default:summary[not(text())] This increases the size of the NodeList by the number of empty text nodes and solved my problem. - Tod |
| Free embeddable forum powered by Nabble | Forum Help |