Loading ...
Sorry, an error occurred while loading the content.

Re: document fragment (getElementById)

Expand Messages
  • lemmsjid
    ... Sorry, this was me making typos ( should have cut and pasted). ... var XMLString = ; var Doc = parseXML(XMLString);
    Message 1 of 10 , Mar 2, 2002
    • 0 Attachment
      --- In svg-developers@y..., "pilatfr" <pilat@w...> wrote:
      > --- In svg-developers@y..., "lemmsjid" <superaltern@h...> wrote:
      >
      > > var XMLString = "<svg><svg id="exampleID"></svg></svg>";
      > >
      > > var DocFrag = parseXML(XMLString);
      > > var element = Node.getElementById("exampleId");
      > > var elementTwo = Node.childNodes.item(0);
      > >
      > > alert(printNode(DocFrag));
      > > alert(printNode(element));
      > > alert(pinrtNode(elementTwo));
      > >
      >
      > Your id is "exampleID" and you use "exampleId" in getElementById ??
      > What is value of Node?
      >
      > Michel

      Sorry, this was me making typos ( should have cut and pasted).

      Let me update this example :):

      -------------------------

      var XMLString = "<svg><svg id="exampleId"></svg></svg>";

      var Doc = parseXML(XMLString);
      var element = Doc.getElementById("exampleId");
      var elementTwo = Doc.childNodes.item(0);

      alert(printNode(Doc));
      alert(printNode(element));
      alert(pinrtNode(elementTwo));
    • pilatfr
      ... When you use only parseXML(s), s is not in DOM, so you get null with getElementById ... Example where s is append to DOM and getElementById run : var
      Message 2 of 10 , Mar 3, 2002
      • 0 Attachment
        --- In svg-developers@y..., "lemmsjid" <superaltern@h...> wrote:
        > var XMLString = "<svg><svg id="exampleId"></svg></svg>";
        >
        > var Doc = parseXML(XMLString);
        > var element = Doc.getElementById("exampleId");
        > var elementTwo = Doc.childNodes.item(0);
        >
        > alert(printNode(Doc));
        > alert(printNode(element));
        > alert(pinrtNode(elementTwo));

        When you use only parseXML(s), s is not in DOM, so you get null with
        getElementById ...

        Example where s is append to DOM and getElementById run :

        var XMLString = "<svg><svg id='exampleId'></svg></svg>";
        svgdoc=evt.getTarget().getOwnerDocument();
        var data = parseXML(XMLString,svgdoc);
        svgdoc.appendChild(data);
        var element = svgdoc.getElementById("exampleId");
        alert("Element "+printNode(element));

        Michel
      • lemmsjid
        ... with ... That is true, but according to the spec (as I understand it), when you use parseXML() with a single argument (that arguement being an XML
        Message 3 of 10 , Mar 4, 2002
        • 0 Attachment
          --- In svg-developers@y..., "pilatfr" <pilat@w...> wrote:
          > --- In svg-developers@y..., "lemmsjid" <superaltern@h...> wrote:
          > > var XMLString = "<svg><svg id="exampleId"></svg></svg>";
          > >
          > > var Doc = parseXML(XMLString);
          > > var element = Doc.getElementById("exampleId");
          > > var elementTwo = Doc.childNodes.item(0);
          > >
          > > alert(printNode(Doc));
          > > alert(printNode(element));
          > > alert(pinrtNode(elementTwo));
          >
          > When you use only parseXML(s), s is not in DOM, so you get null
          with
          > getElementById ...
          >
          > Example where s is append to DOM and getElementById run :
          >
          > var XMLString = "<svg><svg id='exampleId'></svg></svg>";
          > svgdoc=evt.getTarget().getOwnerDocument();
          > var data = parseXML(XMLString,svgdoc);
          > svgdoc.appendChild(data);
          > var element = svgdoc.getElementById("exampleId");
          > alert("Element "+printNode(element));
          >
          > Michel

          That is true, but according to the spec (as I understand it), when
          you use "parseXML()" with a single argument (that arguement being an
          XML string) you get back an XML Document object which is separate
          from the main document object (which, in Adobe, is always the SVG
          image itself). The Adobe Viewer seems to conform to spec--if you
          parse a string using "parseXML(string)" and use "printNode" on it,
          you will see that it has a full XML Document declaration in it. If
          you parse a string using "parseXML(string,svgDocument)" the result
          will not have an XML Document declaration.

          Here's a link to the "parseXML" command spec:

          http://www.protocol7.com/svg-wiki/default.asp?ParseXml

          Also, if you use "parseXML" with a single argument, the object it
          returns (theoretically an XML Document) exposes the document
          methods. All of those document methods work with the exception
          of "getElementById", which always returns 'null' no matter what I
          feed into it.
        • Niklas Gustavsson
          ... This is the correct behavior since your XML doesn t have a DTD defining the Id attribute :-) /niklas www.protocol7.com [Non-text portions of this message
          Message 4 of 10 , Mar 4, 2002
          • 0 Attachment
            > All of those document methods work with the exception
            > of "getElementById", which always returns 'null' no matter what I
            > feed into it.

            This is the correct behavior since your XML doesn't have a DTD defining the Id attribute :-)

            /niklas
            www.protocol7.com


            [Non-text portions of this message have been removed]
          • Tobias Reif
            ... that s because the spec on the Wiki is a description of ASV s behaviour. http://www.protocol7.com/svg-wiki/default.asp?AdobeSVGViewer : Custom Adobe DOM
            Message 5 of 10 , Mar 4, 2002
            • 0 Attachment
              lemmsjid wrote:

              > The Adobe Viewer seems to conform to spec--


              that's because the "spec" on the Wiki is a description of ASV's behaviour.

              http://www.protocol7.com/svg-wiki/default.asp?AdobeSVGViewer :
              Custom Adobe DOM interfaces supported by Adobe SVG Viewer 3.0:

              * getURL()
              * postURL()
              * parseXML()
              * printNode()

              Those are not (yet(?)) in any W3C spec, AFAIK.

              Tobi


              --

              * peace&love.
              * http://www.pinkjuice.com/
            • Kevin Lindsey
              lemmsjid, ... parseXML() returns a DocumentFragment node type. getElementById() is a method of the Document node type. Both the DocumentFragment interface
              Message 6 of 10 , Mar 4, 2002
              • 0 Attachment
                lemmsjid,

                > Also, if you use "parseXML" with a single argument, the object it
                > returns (theoretically an XML Document) exposes the document
                > methods. All of those document methods work with the exception
                > of "getElementById", which always returns 'null' no matter what I
                > feed into it.

                parseXML() returns a DocumentFragment node type. getElementById() is a method of the Document node type. Both the DocumentFragment interface and the Document interface inherit from the Node interface. This implies that DocumentFragment does not have a getElementById() method. I would expect an exception (or some kind of error) to be thrown instead of getting a return value. That seems misleading to me.

                Kevin


                [Non-text portions of this message have been removed]
              • lemmsjid
                ... is a method of the Document node type. Both the DocumentFragment interface and the Document interface inherit from the Node interface. This implies that
                Message 7 of 10 , Mar 5, 2002
                • 0 Attachment
                  --- In svg-developers@y..., "Kevin Lindsey" <kevin@k...> wrote:
                  > lemmsjid,
                  >
                  > > Also, if you use "parseXML" with a single argument, the object it
                  > > returns (theoretically an XML Document) exposes the document
                  > > methods. All of those document methods work with the exception
                  > > of "getElementById", which always returns 'null' no matter what I
                  > > feed into it.
                  >
                  > parseXML() returns a DocumentFragment node type. getElementById()
                  is a method of the Document node type. Both the DocumentFragment
                  interface and the Document interface inherit from the Node
                  interface. This implies that DocumentFragment does not have a
                  getElementById() method. I would expect an exception (or some kind
                  of error) to be thrown instead of getting a return value. That seems
                  misleading to me.
                  >
                  > Kevin
                  >
                  >
                  > [Non-text portions of this message have been removed]

                  Kevin,

                  parseXML() returns an actual Document object IF you do not pass
                  another document as the second parameter. If you check its properties
                  you will find that the node type is "Document" rather than "Document
                  Fragment" (which is indeed returned if you use parseXML with a
                  document as the second parameter). If you use two parameters (first
                  an XML string and then the Document you wish to append it to), the
                  Document methods are not exposed, as is proper.

                  Niklas,

                  I had not thought of specifying a DTD -- I didn't realize the Adobe
                  Viewer would require such a thing (other renditions of the DOM I've
                  used haven't required DTD's to get to an element's ID att). Good
                  idea, I'll check it out.

                  Junor
                • Kevin Lindsey
                  Junor, ... Ah, yes. I see that now. I tested the resulting node type using two parameters only. Thanks for the correction. Kevin
                  Message 8 of 10 , Mar 5, 2002
                  • 0 Attachment
                    Junor,

                    > parseXML() returns an actual Document object IF you do not pass
                    > another document as the second parameter.

                    Ah, yes. I see that now. I tested the resulting node type using two
                    parameters only.

                    Thanks for the correction.

                    Kevin
                  Your message has been successfully submitted and would be delivered to recipients shortly.