--- In svg-developers@yahoogroups.com, "samcctan" <[EMAIL PROTECTED]> wrote:

> " As the SVG DTD defines its attributes in an external DTD you will 
> not get Mozilla to look at it at all and therefore Mozilla (at least 
> in not SVG enabled builds) will not know about attributes of type ID 
> in SVG documents and thus getElementById does not find anything."
> 
> Is that means since i am using external DTD, therefore I couldn't use 
> getElementById for my case? If so, is there anyway I can make my SVG 
> DTD define its attributes "internally" so that Mozilla able to look 
> at it and know about attributes of type ID in my SVG documents?

If you are using a SVG enabled Mozilla build then I think
getElementById should work for SVG elements even if the DTD is not
read, the same way it works for XHTML.

If you are not using an SVG enabled Mozilla build and load normal XML
then you could use XPath to find a matching element with an id
attribute e.g.

function getElementById (xmlDocument, idValue, idAttributeName) {
  if (typeof idAttributeName == 'undefined') {
    idAttributeName = 'id';
  }
  var xpathResult = xmlDocument.evaluate(
    '//*[@' + idAttributeName + ' = "' + idValue + '"]',
    xmlDocument,
    null,
    9,
    null
  );
  if (xpathResult.singleNodeValue != null) {
    return xpathResult.singleNodeValue;
  }
  else {
    return null;
  }
}

var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', 'whatever.xml', true);
httpRequest.onreadystatechange = function () {
  if (httpRequest.readyState == 4 && httpRequest.status == 200) {
    var xmlDocument = httpRequest.responseXML;
    var element = getElementById(xmlDocument, 'elementid');
    alert(element);
  }
};
httpRequest.send(null);


As for getting Mozilla to read the DTD that is a lot of work, you
would need to write an internal DTD that defines the attribute of name
id to be of type ID for all the elements in SVG.





-----
To unsubscribe send a message to: [EMAIL PROTECTED]
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my 
membership"
---- 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/svg-developers/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to