[MOBY-dev] Perl question
Andreas Groscurth
groscurt at mpiz-koeln.mpg.de
Mon Jun 11 09:49:30 UTC 2007
Awesome :-)
works fine.. thanks for that
Andreas
On Friday 08 June 2007 15:37, Edward Kawas wrote:
> Actually, I guess that I haven't had all my coffee yet, because the 'right'
> way does work (but not if you include other stuff in the URI!)
>
> Here is the code:
>
> my $parser = XML::LibXML->new();
> $parser->clean_namespaces(1);
> my $doc = $parser->parse_string($stuff);
> my $root = $doc->getDocumentElement;
>
> my @objectNodes = ();
>
> # $outObjType = Object (!)
> @objectNodes = $root->findnodes("//moby:Object");
>
> # deal with 'moby-less' xml tags:
> @objectNodes = $root->findnodes("//Object") unless @objectNodes;
> my $resCnt = 0;
>
> # a result counter, used as default for file naming
> # iterate over all result objects
> foreach my $objectNode (@objectNodes) {
> my ( $ns, $id );
> if ( $objectNode->hasAttributeNS( 'http://www.biomoby.org/moby',
> 'namespace' ) ) {
> $ns = $objectNode->getAttributeNS(
> 'http://www.biomoby.org/moby', 'namespace' );
> }
> elsif ( $objectNode->hasAttribute('namespace') ) {
> $ns = $objectNode->getAttribute('namespace');
>
> }
> print $ns;
> }
>
> Eddie
>
> > -----Original Message-----
> > From: moby-dev-bounces at lists.open-bio.org [mailto:moby-dev-
> > bounces at lists.open-bio.org] On Behalf Of Andreas Groscurth
> > Sent: Friday, June 08, 2007 5:21 AM
> > To: moby-dev at lists.open-bio.org
> > Subject: [MOBY-dev] Perl question
> >
> > Hiho,
> >
> > because of the awesome perl hackers on the list.. I hope someone can help
> > me....
> >
> > I have the following Moby response
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <moby:MOBY xmlns:moby="http://www.biomoby.org/moby">
> > <moby:mobyContent>
> > <moby:mobyData moby:queryID="sip_1_">
> > <moby:Collection moby:articleName="pubmedID">
> > <moby:Simple>
> > <moby:Object moby:id="" moby:namespace="PMID_" />
> > </moby:Simple>
> > <moby:Simple>
> > <moby:Object moby:id="7743940 " moby:namespace="PMID_" />
> > </moby:Simple>
> > <moby:Simple>
> > <moby:Object moby:id="9090879 " moby:namespace="PMID_" />
> > </moby:Simple>
> > <moby:Simple>
> > <moby:Object moby:id="9090880 " moby:namespace="PMID_" />
> > </moby:Simple>
> > </moby:Collection>
> > </moby:mobyData>
> > </moby:mobyContent>
> > </moby:MOBY>
> >
> > and the following perl code
> >
> > my $parser = XML::LibXML->new();
> > $parser->clean_namespaces( 1 );
> > my $doc = $parser->parse_string($resultXML);
> > my $root = $doc->getDocumentElement;
> >
> > my @objectNodes = ();
> > # $outObjType = Object (!)
> > @objectNodes = $root->findnodes("//moby:$outObjType");
> > # deal with 'moby-less' xml tags:
> > @objectNodes = $root->findnodes("//$outObjType") unless @objectNodes;
> > my $resCnt = 0; # a result counter, used as default for file naming
> > # iterate over all result objects
> > foreach my $objectNode (@objectNodes) {
> > # create a filename and write the object to the cache directory
> >
> > # if provider uses other namespaces (that is other
> > # than the start namespace of the application), get
> > # this and use it for cache file name
> > my ($ns,$id);
> > if ( $objectNode->hasAttributeNS('moby', 'namespace') ) {
> > $ns = $objectNode->getAttributeNS('moby', 'namespace');
> > }
> > # deal with 'moby-less' attributes
> > elsif ( $objectNode->hasAttribute('namespace') ) {
> > $ns = $objectNode->getAttribute('namespace');
> > }
> >
> > as far as I understand this code (is from Dirks aggregator), it should
> > parse
> > the namespace of the element 'moby:Object'... but it doesnt.
> >
> > I know nothing about LibXML and parsing xml in Perl.. so I was wondering,
> > why
> >
> > if ( $objectNode->hasAttributeNS('moby', 'namespace') ) {
> > $ns = $objectNode->getAttributeNS('moby', 'namespace');
> > }
> >
> > is not working.
> >
> > Any hints ?
> >
> > Thanks
> > Andreas
> >
> > _______________________________________________
> > MOBY-dev mailing list
> > MOBY-dev at lists.open-bio.org
> > http://lists.open-bio.org/mailman/listinfo/moby-dev
>
> _______________________________________________
> MOBY-dev mailing list
> MOBY-dev at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/moby-dev
--
Andreas Groscurth
Diplom Bioinformatik - PhD Student
Max Planck Institute for Plant Breeding Research
Carl-von-Linné-Weg 10
50829 Cologne
Germany
E-mail: groscurt at mpiz-koeln.mpg.de
Phone: +49(0)221-5062-447
More information about the MOBY-dev
mailing list