# Problem writing all of XML file to page, using javascript

**URL:** <https://forum.kirupa.com/t/problem-writing-all-of-xml-file-to-page-using-javascript/319160>\
**Category:** Uncategorized\
**Created:** [February 10, 2011, 2:32pm UTC](https://forum.kirupa.com/t/problem-writing-all-of-xml-file-to-page-using-javascript/319160 "2011-02-10T14:32:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![graylensman](https://avatars.discourse-cdn.com/v4/letter/g/5f9b8f/32.png) [@graylensman](https://forum.kirupa.com/u/graylensman)\
**Post date:** [February 10, 2011, 2:32pm UTC](https://forum.kirupa.com/t/problem-writing-all-of-xml-file-to-page-using-javascript/319160/1 "2011-02-10T14:32:35Z")

</div>

I’m working on importing XML data to a webpage, using javascript function. I’ve gotten it to work, mostly. The problem is this: I can’t get it to write all the data in the XML file.

Here’s an exerpt from an XML file I’m using:

```php
<program>
	<character>
		<named>Kirk</named>
		<rank>Captain</rank>
		<show>Star Trek</show>
	</character>
	<character>
		<named>Spock</named>
		<rank>Commander</rank>
		<show>Star Trek</show>
	</character>
	<character>
		<named>McCoy</named>
		<rank>Commander</rank>
		<show>Star Trek</show>
	</character>
</program>

```

Here’s my javascript function:

```php
function getTheFile(theFile){ 
xmlhttp.open("GET",theFile,false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML; 

person=xmlDoc.getElementsByTagName("character");
for(i=0;i<person.length; i++){
	char=(person*.getElementsByTagName("named")[0].childNodes[0].nodeValue);
	ranked=(person*.getElementsByTagName("rank")[0].childNodes[0].nodeValue);
	shown=(person*.getElementsByTagName("show")[0].childNodes[0].nodeValue);
	txt="<h2>" +char + "</h2><p>" + ranked + "<br />"+ shown +"</p>";
	document.getElementById("showGuy").innerHTML=txt;
	}
}
</script>

```

The end result is - the function writes the last group of tags and nothing else:

```php
McCoy
Commander
Star Trek

```

For the life of me, I cannot figure out how to write everything else. Help me! Thanks
