You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by Gul Akbar <G....@Bradford.ac.uk> on 2003/03/30 01:45:19 UTC
Fwd: XPath for Xindice
Hi,
Ive just joined this mailing list and I have a question regarding XPath and
namespaces which I am trying to achive through a Java class.
Below, I have included the XML docuement in my database which I am trying to
query.
Basically there are many namespaces declared in the root node, and I was
wondering how the XPathQueryServive interface can handle this.
The XPath:
----------------
//mets[ /mets/metsHdr/agent/name='Gul Akbar' ]
----------------
However this returns no results.
The Java part (ive tried with and without setNamespaces - both returning no
results). Later I want to try getting the tags that have ETOC namespace (see
below).
----------------
XPathQueryService service = (XPathQueryService) col.getService
("XPathQueryService", "1.0");
service.setNamespace("xmlns","http://www.loc.gov/METS/");
service.setNamespace("xmlns:xlink","http://www.w3.org/TR/xlink");
service.setNamespace("xmlns:DC","http://purl.org/dc/elements/1.1/");
service.setNamespace
("xmlns:ETOC","http://localhost:8080/Project/xsd/etoc.xsd");
service.setNamespace("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
service.setNamespace("xsi:schemaLocation","http://www.loc.gov/METS/
http://www.loc.gov/standards/mets/mets.xsd
http://purl.org/dc/elements/1.1/
http://dublincore.org/schemas/xmls/simpledc20021212.xsd");
System.out.println("xmlns: "+ service.getNamespace("xmlns"));
System.out.println("xlink: "+ service.getNamespace("xlink"));
System.out.println("DC: "+ service.getNamespace("DC"));
System.out.println("ETOC: "+ service.getNamespace("ETOC"));
System.out.println("xsi: "+ service.getNamespace("xsi"));
System.out.println("schemaLocation: "+
service.getNamespace("schemaLocation"));
ResourceSet resultSet = service.query(xpath);
ResourceIterator results = resultSet.getIterator();
----------------
The record in question.
----------------
<?xml version="1.0"?>
<mets xmlns="http://www.loc.gov/METS/"
xmlns:xlink="http://www.w3.org/TR/xlink"
xmlns:DC="http://purl.org/dc/elements/1.1/"
xmlns:ETOC="http://localhost:8080/Project/xsd/etoc.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.loc.gov/METS/
http://www.loc.gov/standards/mets/mets.xsd
http://purl.org/dc/elements/1.1/
http://dublincore.org/schemas/xmls/simpledc20021212.xsd">
<metsHdr>
<agent ROLE="CREATOR" TYPE="INDIVIDUAL">
<name>Gul Akbar</name>
</agent>
</metsHdr>
<dmdSec ID="ART_DMDID_DC">
<mdWrap MDTYPE="DC">
<xmlData>
<DC:identifier>RN087521709</DC:identifier>
</xmlData>
</mdWrap>
</dmdSec>
<dmdSec ID="ART_DMDID_ETOC">
<mdWrap MDTYPE="OTHER" OTHERMDTYPE="ETOC">
<xmlData>
<ETOC:ATI>BRV</ETOC:ATI>
<ETOC:ID>RN087521709</ETOC:ID>
<ETOC:ISSUE>2000; VOL 9; PART 3</ETOC:ISSUE>
<ETOC:LANG>E</ETOC:LANG>
<ETOC:PAGE>189-200</ETOC:PAGE>
<ETOC:TEXT>Book review/viewpoint on Ian Angell's book- `The New
Barbarian Manifesto: How to Survive in the Information Age'
</ETOC:TEXT>
</xmlData>
</mdWrap>
</dmdSec>
<amdSec>
<rightsMD ID="ART_ADMID1">
<mdWrap MDTYPE="DC">
<xmlData>
<DC:rights>Copyright is owned by the publisher</DC:rights>
</xmlData>
</mdWrap>
</rightsMD>
</amdSec>
<structMap>
<div TYPE="ARTICLE" DMDID="ART_DMDID_ETOC ART_DMDID_DC" ADMID="ART_ADMID1">
<mptr LOCTYPE="URN" xlink:type="simple" xlink:href="RN087521709.xml" />
</div>
</structMap>
</mets>
----------------
I have used XML Spy 5 and used the XPath creator to test the above XPath, and
that seems to be picking it up. Im definately doing something wrong in the
Java, as far as I know.
Ive attached the record and the Java class.
Can anyone help me?
Thanks in advance.
Gul Akbar
-------------------------------------------------
This mail sent through IMP: webmail.brad.ac.uk
Re: XPath for Xindice
Posted by Gul Akbar <G....@Bradford.ac.uk>.
Hi,
I have now found that the XPath is wrong. I tried the XPath in an XSL and it
didnt pick the node up. Is there a good site I can look at, or examples for XSL
(XPath) for the namespace tags? I think if I can sort the XPath out first in
XSL then I'l use the XPathQueryService class.
Does anyone know the XPath to the <name> and <ETOC:TEXT> tags in the attached
document?
Thanks
Gul
Quoting Gianugo Rabellino <gi...@apache.org>:
> Gul Akbar wrote:
> > I have tried removing all the occurences of the namespace in the XML
> records,
> > and the XPath works fine. So this leaves me to believe that there must
> be
> > something to do with the XPathQueryService class and the way it
> detects
> > namespaces.
> >
> > Has anyone come across this before.
> >
>
> AFAIK namespaces work just fine: we rely on the Xalan engine, so
> basically if they work with XSLT they should work with Xindice, so I
> tend to suspect that there is something wrong in your code or in your
> documents. Have you removed the following line?
>
> service.setNamespace("xmlns","http://www.loc.gov/METS/");
>
> Ciao,
>
> --
> Gianugo Rabellino
> Pro-netics s.r.l.
> http://www.pro-netics.com
>
>
-------------------------------------------------
This mail sent through IMP: webmail.brad.ac.uk
Re: XPath for Xindice
Posted by Gianugo Rabellino <gi...@apache.org>.
Gul Akbar wrote:
> I have tried removing all the occurences of the namespace in the XML records,
> and the XPath works fine. So this leaves me to believe that there must be
> something to do with the XPathQueryService class and the way it detects
> namespaces.
>
> Has anyone come across this before.
>
AFAIK namespaces work just fine: we rely on the Xalan engine, so
basically if they work with XSLT they should work with Xindice, so I
tend to suspect that there is something wrong in your code or in your
documents. Have you removed the following line?
service.setNamespace("xmlns","http://www.loc.gov/METS/");
Ciao,
--
Gianugo Rabellino
Pro-netics s.r.l.
http://www.pro-netics.com
Re: XPath for Xindice
Posted by Gul Akbar <G....@Bradford.ac.uk>.
I have tried removing all the occurences of the namespace in the XML records,
and the XPath works fine. So this leaves me to believe that there must be
something to do with the XPathQueryService class and the way it detects
namespaces.
Has anyone come across this before.
Quoting Gul Akbar <G....@Bradford.ac.uk>:
> Thanks for the response.
>
> However, I am still having a few problems with the XPath itself. I
> altered the
> setNamespace() method to follow those described below, however, it still
> return
> no results. Is there any way in which you can find out what Xindice is
> doing in
> terms of matching the records, like a printStackTrace or something?
>
> Im still getting no results even though the XPath is correct in
> XML-Spy-5
>
> Thanks
> Gul
-------------------------------------------------
This mail sent through IMP: webmail.brad.ac.uk
Re: Fwd: XPath for Xindice
Posted by Gul Akbar <G....@Bradford.ac.uk>.
Thanks for the response.
However, I am still having a few problems with the XPath itself. I altered the
setNamespace() method to follow those described below, however, it still return
no results. Is there any way in which you can find out what Xindice is doing in
terms of matching the records, like a printStackTrace or something?
Im still getting no results even though the XPath is correct in XML-Spy-5
Thanks
Gul
Quoting Gianugo Rabellino <gi...@apache.org>:
> Gul Akbar wrote:
> > service.setNamespace("xmlns","http://www.loc.gov/METS/");
> > service.setNamespace("xmlns:xlink","http://www.w3.org/TR/xlink");
> >
> service.setNamespace("xmlns:DC","http://purl.org/dc/elements/1.1/");
> > service.setNamespace
> > ("xmlns:ETOC","http://localhost:8080/Project/xsd/etoc.xsd");
>
> All these should be:
>
> service.setNamespace("xlink","http://www.w3.org/TR/xlink");
> service.setNamespace("DC","http://purl.org/dc/elements/1.1/");
> ...
>
> removing the "xmlns" keyword that is not part of the namespace prefix.
>
> > service.setNamespace("xsi:schemaLocation","http://www.loc.gov/METS/
>
> > http://www.loc.gov/standards/mets/mets.xsd
> > http://purl.org/dc/elements/1.1/
> >
> http://dublincore.org/schemas/xmls/simpledc20021212.xsd");
>
> This is *not* a namespace decl. It's just the attribute "schemaLocation"
>
> in the namespace "http://www.w3.org/2001/XMLSchema-instance", identified
>
> by the prefix "xsi".
>
> HTH,
>
> --
> Gianugo Rabellino
> Pro-netics s.r.l.
> http://www.pro-netics.com
>
>
-------------------------------------------------
This mail sent through IMP: webmail.brad.ac.uk
Re: Fwd: XPath for Xindice
Posted by Gianugo Rabellino <gi...@apache.org>.
Gul Akbar wrote:
> service.setNamespace("xmlns","http://www.loc.gov/METS/");
> service.setNamespace("xmlns:xlink","http://www.w3.org/TR/xlink");
> service.setNamespace("xmlns:DC","http://purl.org/dc/elements/1.1/");
> service.setNamespace
> ("xmlns:ETOC","http://localhost:8080/Project/xsd/etoc.xsd");
All these should be:
service.setNamespace("xlink","http://www.w3.org/TR/xlink");
service.setNamespace("DC","http://purl.org/dc/elements/1.1/");
...
removing the "xmlns" keyword that is not part of the namespace prefix.
> service.setNamespace("xsi:schemaLocation","http://www.loc.gov/METS/
> http://www.loc.gov/standards/mets/mets.xsd
> http://purl.org/dc/elements/1.1/
> http://dublincore.org/schemas/xmls/simpledc20021212.xsd");
This is *not* a namespace decl. It's just the attribute "schemaLocation"
in the namespace "http://www.w3.org/2001/XMLSchema-instance", identified
by the prefix "xsi".
HTH,
--
Gianugo Rabellino
Pro-netics s.r.l.
http://www.pro-netics.com