Quantcast

Confirmation of xml:id behaviour

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Confirmation of xml:id behaviour

Cameron McCormack-4

Hi.

Can I confirm that with the following document, “true” will be alerted,
yes?

  <svg xmlns='http://www.w3.org/2000/svg' xml:id='1'>
    <script>
      alert(document.getElementById('0') == document.documentElement);
    </script>
  </svg>

Thanks,

Cameron

--
Cameron McCormack, http://mcc.id.au/
        xmpp:[hidden email]  ▪  ICQ 26955922  ▪  MSN [hidden email]

Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Confirmation of xml:id behaviour

Daniel Veillard

On Tue, Feb 12, 2008 at 04:31:50PM +1100, Cameron McCormack wrote:

>
> Hi.
>
> Can I confirm that with the following document, “true” will be alerted,
> yes?
>
>   <svg xmlns='http://www.w3.org/2000/svg' xml:id='1'>
>     <script>
>       alert(document.getElementById('0') == document.documentElement);
>     </script>
>   </svg>

  All I can say from an xml:id point of view is that the svg element
will be reported as having an attribute xml:id of type ID to the
application processing the document and that the value of this
ID is '1' (not '0').
  Everything else you seems to assume looks dependand on how the
application interpret the XML, including the svg and script element,
and that xml:id cannot garantee it in itself.

  If I try to make assumptions about how that interpretation occurs
it seems to me document.getElementById('0') is not gonna return a
node, so the equlity will fail and the behaviour will be the same as
an alert for "false", but that's just interpretation based on a lot of
assumptions ...

Daniel

--
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
[hidden email]  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/

Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Confirmation of xml:id behaviour

Cameron McCormack-4

Hi Daniel.

Daniel Veillard:
>   All I can say from an xml:id point of view is that the svg element
> will be reported as having an attribute xml:id of type ID to the
> application processing the document and that the value of this
> ID is '1' (not '0').

Sorry, yeah meant to write '1' there, not '0'.

>   Everything else you seems to assume looks dependand on how the
> application interpret the XML, including the svg and script element,
> and that xml:id cannot garantee it in itself.

OK, so given Document.getElementById() says:

  Returns the Element that has an ID attribute with the given value. If
  no such element exists, this returns null.
    — http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-getElBId

I think it should alert true.

It just seemed surprising to me that invalid IDs were effectively
treated the same as valid ones, but if that’s what’s meant to happen,
I’ll go with it.

Thanks,

Cameron

--
Cameron McCormack, http://mcc.id.au/
        xmpp:[hidden email]  ▪  ICQ 26955922  ▪  MSN [hidden email]

Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Confirmation of xml:id behaviour

Daniel Veillard

On Tue, Feb 12, 2008 at 10:25:10PM +1100, Cameron McCormack wrote:

>
> Hi Daniel.
>
> Daniel Veillard:
> >   All I can say from an xml:id point of view is that the svg element
> > will be reported as having an attribute xml:id of type ID to the
> > application processing the document and that the value of this
> > ID is '1' (not '0').
>
> Sorry, yeah meant to write '1' there, not '0'.
>
> >   Everything else you seems to assume looks dependand on how the
> > application interpret the XML, including the svg and script element,
> > and that xml:id cannot garantee it in itself.
>
> OK, so given Document.getElementById() says:
>
>   Returns the Element that has an ID attribute with the given value. If
>   no such element exists, this returns null.
>     — http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-getElBId
>
> I think it should alert true.
>
> It just seemed surprising to me that invalid IDs were effectively
> treated the same as valid ones, but if that’s what’s meant to happen,
> I’ll go with it.

  http://www.w3.org/TR/xml-id/#processing

  ------------------
  Each xml:id attribute is processed in the following way:
   ...
     - ID type assignment is performed with the normalized value.
   ...
  An xml:id processor must assure that the following constraints hold for all xml:id attributes:
     - The normalized value of the attribute is an NCName  ...

  An xml:id error occurs for any xml:id attribute that does not satisfy the constraints.
  ------------------

Hence to me the ID type assigment is done and reported to the application (that
is beginning of section 5), and an error MUST be reported to the application.
So the application get both informations. I would expect the IDness to stick
and getElementById() to work. How and if the application will report the error
sounds very dependant of the kind of application (an editor definitely should).

For the anecdote, for a long long time I tried in libxml2 to no pass non-NCNames
as ID to the applications, and got persistent continuous reports that
applications expected to see the malformed IDs anyway (this has been buried in
existing processes :-( ) and in the end I changed. You get the error as a
validity kind of warning in libxml2 since this correspond to a validity
checking for XML-1.0.

Daniel


--
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
[hidden email]  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/

Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Confirmation of xml:id behaviour

Norman Walsh
In reply to this post by Cameron McCormack-4
[ Sorry for the tardy reply; life has been ... interesting :-) ]

/ Cameron McCormack <[hidden email]> was heard to say:
| Daniel Veillard:
|>   Everything else you seems to assume looks dependand on how the
|> application interpret the XML, including the svg and script element,
|> and that xml:id cannot garantee it in itself.
|
| OK, so given Document.getElementById() says:
|
|   Returns the Element that has an ID attribute with the given value. If
|   no such element exists, this returns null.
|     — http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-getElBId
|
| I think it should alert true.

So do I.

| It just seemed surprising to me that invalid IDs were effectively
| treated the same as valid ones, but if that’s what’s meant to happen,
| I’ll go with it.

Yes, that's what's meant to happen. An invalid ID is an error, but if
you ignore the error, you get an attribute of type ID even if the
normalized string value is not a valid XML ID.

                                        Be seeing you,
                                          norm

--
Norman Walsh <[hidden email]> | Truth lies within a little uncertain
http://nwalsh.com/            | compass, but error is immense.

attachment0 (191 bytes) Download Attachment
Loading...