Is a method supported document.getElementByIdin the DOM parsed from XML strings using the DOMParser method in Mozilla? I am making a Mozilla extension that reads an XML file and uses the DOM Parser to convert the XML to a DOM element and tries to get the elements by Id. The getElementsByTagName method works, but not getElementById. Always returns zero.
document.getElementById
function (xmlString) { var parser = new DOMParser(); var doc = parser.parseFromString(xmlString, "text/xml"); var aNodes = doc.getElementsByTagName("nodeTag"); for(var i=0; i<aNodes.length; ++i) { var id = aNodes[i].getAttribute('id'); var resultNode = doc.getElementById(id); alert(id); alert(resultNode); } }
I tried the code above. alert (id) returns the correct identifier, while alert (resultNode) returns null each time.
, document.getElementById XML-.
(, Firefox 3.5 ) document.querySelector:
document.querySelector
var resultNode = doc.querySelector("[id=" + id + "]");
, getElementById() ( , ), DTD, :
<!ATTLIST client id ID #IMPLIED >
DTD, xml <?xml version= \"1.0\"?>:
<?xml version= \"1.0\"?>
<!DOCTYPE clients [ <!ATTLIST client id ID #IMPLIED > ]>
"" - xml , "" - , . "ATTLIST" , id .
, firefox. .
Source: https://habr.com/ru/post/1763777/More articles:How to wait for the completion of the GWT RPC? - rpcLogging problem with two ears Log4j in Weblogic - javaGWT blocks RPC - javamaven: удаление форматированного файла из созданной сборки - fileHow to select a rectangular area in the visual block mode (Ctrl + v) in an empty file (vim)? - vimChart using scrollview in android - androidglGenLists and iOS - iosstl and exceptions - c ++syntax error, unexpected T_RETURN, waiting for T_FUNCTION oop php - phpjcarousel - how can I make the image link in the carousel stay active? - jqueryAll Articles