List Info

Thread: Re: can't use DOM methods in XML::LibXML when parsing from file...




Re: can't use DOM methods in XML::LibXML when parsing from file...
country flaguser name
Germany
2007-05-09 17:16:01
Hi Anthony,

* Anthony Ettinger <anthonychovy.com> [2007-05-09
23:00]:
> It still however ($doc->getElementById) does not
work on xml
> (specifically a docbook file I'm using).
> 
> <?xml version="1.0"
encoding="UTF-8"?>
> <book lang="en">
>     <bookinfo>
>         <title>Foobar Doc</title>
>     </bookinfo>
>     <chapter id="foobar">
>         <title>Sub Title of Foobar</title>
>         <para>Blah blah</para>
>     </chapter>
> </book>
> 
> I get an undefined object when I call
$doc->getElementById('foobar');
> 
> There is an explanation here, but I cannot make sense
of it:
> http://cpan.uwinnipeg.ca
/htdocs/XML-LibXML/Document.pm.html#strong_getElementById_st
rong

The fact that the attribute is called `id` is irrelevant to
whether it is an ID. It must be defined as an `IDREF`
attribute
in the DTD for the document. That means that without finding
a
DTD declaration and parsing the DTD, the XML parser does not
know
which attributes are IDs. So as far as the parser is
concerned,
there is no element with the ID `foobar` in the above
document,
and thus you get undef. Everything is working as expected.

If using the DTD is not an option in your case for whatever
reason, you could duplicate the ID in a redundant `xml:id`
attribute:

        <chapter id="foobar"
xml:id="foobar">

Since `xml:id` is predefined as an IDREF, XML parsers that
conform to the xml:id spec not need a DTD to know that the
element above has the ID `foobar`.

However, I am not sure what reaction a parser will have if
it has
read the DTD and sees that the same ID is declared on the
same
element in two different ways.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/&g
t;
_______________________________________________
Perl-XML mailing list
Perl-XMLlistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

Re: can't use DOM methods in XML::LibXML when parsing from file...
user name
2007-05-09 17:48:35
On 5/9/07, A. Pagaltzis <pagaltzisgmx.de> wrote:
> Hi Anthony,
>
> * Anthony Ettinger <anthonychovy.com> [2007-05-09
23:00]:
> > It still however ($doc->getElementById) does
not work on xml
> > (specifically a docbook file I'm using).
> >
> > <?xml version="1.0"
encoding="UTF-8"?>
> > <book lang="en">
> >     <bookinfo>
> >         <title>Foobar Doc</title>
> >     </bookinfo>
> >     <chapter id="foobar">
> >         <title>Sub Title of
Foobar</title>
> >         <para>Blah blah</para>
> >     </chapter>
> > </book>
> >
> > I get an undefined object when I call
$doc->getElementById('foobar');
> >
> > There is an explanation here, but I cannot make
sense of it:
> > http://cpan.uwinnipeg.ca
/htdocs/XML-LibXML/Document.pm.html#strong_getElementById_st
rong
>
> The fact that the attribute is called `id` is
irrelevant to
> whether it is an ID. It must be defined as an `IDREF`
attribute
> in the DTD for the document. That means that without
finding a
> DTD declaration and parsing the DTD, the XML parser
does not know
> which attributes are IDs. So as far as the parser is
concerned,
> there is no element with the ID `foobar` in the above
document,
> and thus you get undef. Everything is working as
expected.
>
> If using the DTD is not an option in your case for
whatever
> reason, you could duplicate the ID in a redundant
`xml:id`
> attribute:
>
>         <chapter id="foobar"
xml:id="foobar">
>
> Since `xml:id` is predefined as an IDREF, XML parsers
that
> conform to the xml:id spec not need a DTD to know that
the
> element above has the ID `foobar`.
>
> However, I am not sure what reaction a parser will have
if it has
> read the DTD and sees that the same ID is declared on
the same
> element in two different ways.
>

Ok, so if I validate, I can use 'id="foobar"', if
I don't validate, I
have to use 'xml:id="foobar"'

Now, supposing (and this may be OT) I want to use xml schema
or
relaxNG to validate instead of a DTD, what is the proper
doctype to
put in my xml docbook file?

-- 
Anthony Ettinger
Ph: 408-656-2473
http://chovy.dynd
ns.org/resume.html
http://utuxia.com/consul
ting
_______________________________________________
Perl-XML mailing list
Perl-XMLlistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )