You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Wei Cheng <We...@baylor.edu> on 2000/11/12 00:53:12 UTC
ask another question
Hi Gary,
Thursday, November 09, 2000, 10:14:42 PM, you wrote:
GLP> Wei Cheng wrote:
>>
>> Hi All,
>> I have tried to use Xalan package to do my master's project.
>> First, I write a primary key fuction to try to test whether XMl
>> document can satisfy the primary key requirement.
>> I modify the example ApplyXpath.java and foo.xml to test my idea.
>> I use foo1.xml as an XMl document input.
>> ...
GLP> Wei --
GLP> Did you ever get an answer on this? If you're trying to do this compare
GLP> in java, I think you can just iterate over the NodeSets with one loop
GLP> nested inside the other.
GLP> BTW, I'd stay away from NodeSet because this is a Xalan invention that
GLP> could change. NodeSet also extends NodeList which is a DOM class and I
GLP> think you'd be better off using that or NodeIterator.
GLP> You could also do this entirely with your XPath. You currently have the
GLP> second XPath as
GLP> /doc/name[1]/following-sibling::name/firstname
GLP> I think you could make it something like
GLP> /doc/name[1]/following-sibling::name/firstname[. !=
GLP> /doc/name[1]/firstname]
GLP> Then, you'd only have one XPath and you'd just have to check if the
GLP> resulting node-set was null or not. If you wanted, you could loop
GLP> through this for each name in doc and dynamically build an XPath,
GLP> changing the subscript in your java program.
GLP> Or, you could use XPath alone to just get a node-set containing all of
GLP> the name elements that contain what you call primary keys:
GLP> /doc/name[firstname != preceding-sibling::name/firstname]
GLP> Haven't tested these expressions, but they should be close.
GLP> Gary
Thanks a lot first! I have tried all these two expressions, for the
second one /doc/name[firstname !=
preceding-sibling::name/firstname],
it seems that I can't get the /doc/name[1]/firstname when I apply
Xpath, I want to test a set of firstname in the doc to see whether
all firstname are different,if yes,I return yes otherwise return
false.
this is my strategy:
If I can get NodeIterator when I apply second Xpath, and
compare with another NodeIterator when I apply /doc/name/firstname,
and I compare each node in these two nodeiterators, to see if the node
order and the value is the same, then return true else false.
but for some reason, /doc/name[1]/firstname doesn't show in the
nodeiterator when I apply second Xpath from you. From the
definition,it should be here. because the /doc/name[1]/firstname's
preceding-sibling should be null.
Can you give me some advice on this or give me other idea for this?
Thanks again!
Best regards,
Wei mailto:Wei_Cheng@baylor.edu