I want to retrieve elements from a large XML-document acquired through an XMLHttpRequest. The response is quite large so adding it to the document/window/website with display set to "none" and then doing a document.querySelectorAll("sometag") on the main document is not doable.
Currently, I have this code:
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
function fetchIds(){
var url = "something";
let request = new XMLHttpRequest();
request.open("POST", url);
request.send();
request.onload = function(){
var ids = request.responseText;
ids = ids.replace(/[<>]|(Id)|(List)|\//gi, "").trim().split("\n").join(",");
return ids;
}
}
fetchIds();
When this returns I get a document of this sort:
<AuthorList CompleteYN="Y">
<Author ValidYN="Y">
<LastName>Idziak-Helmcke</LastName>
<ForeName>Dominika</ForeName>
<Initials>D</Initials>
<Identifier Source="ORCID">0000-0002-0713-2466</Identifier>
<AffiliationInfo>
<Affiliation>Institute of Biology, Biotechnology, and Environmental Sciences, University of Silesia in Katowice, Jagiellońska 28, 40-032 Katowice, Poland.</Affiliation>
</AffiliationInfo>
</Author>
<Author ValidYN="Y">
<LastName>Warzecha</LastName>
<ForeName>Tomasz</ForeName>
<Initials>T</Initials>
<Identifier Source="ORCID">0000-0002-7121-0123</Identifier>
<AffiliationInfo>
<Affiliation>Department of Plant Breeding, Physiology, and Seed Science, University of Agriculture in Kraków, Podłużna 3, 30-239 Kraków, Poland.</Affiliation>
</AffiliationInfo>
</Author>
<Author ValidYN="Y">
<LastName>Sowa</LastName>
<ForeName>Marta</ForeName>
<Initials>M</Initials>
<AffiliationInfo>
<Affiliation>Institute of Biology, Biotechnology, and Environmental Sciences, University of Silesia in Katowice, Jagiellońska 28, 40-032 Katowice, Poland.</Affiliation>
</AffiliationInfo>
</Author>
For the sake of making this question simple, I want to grab all the LastName tags in this XML-document, but I want to do this directly from the request.responseText or the request.responseXML. Is this possible with JavaScript? I have tried doing request.responseXML.querySelectorAll("sometag"), but with no luck.
Any help would be greatly apprecited, thanks!