# \[SOLVED\] TypeError: xml.getChildren is not a function

**URL:** <https://discourse.processing.org/t/solved-typeerror-xml-getchildren-is-not-a-function/1697>\
**Category:** Coding Questions\
**Created:** [July 11, 2018, 7:08pm UTC](https://discourse.processing.org/t/solved-typeerror-xml-getchildren-is-not-a-function/1697 "2018-07-11T19:08:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![T\_mex](https://avatars.discourse-cdn.com/v4/letter/t/74df32/32.png) [@T\_mex](https://discourse.processing.org/u/T_mex)\
**Post date:** [July 11, 2018, 7:08pm UTC](https://discourse.processing.org/t/solved-typeerror-xml-getchildren-is-not-a-function/1697/1 "2018-07-11T19:08:47Z")

</div>

I’m running into an issue when trying to parse an XML file using getChildren().

```auto
 	var xml = new p5.XML();
 	xml = loadXML("XML/UserInfo.xml");
	print(xm.getChildren('User'));

```

The error I’m getting is “TypeError: xmlFile.getChildren is not a function”

But if I run the above in the the web console I don’t see this error.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [July 11, 2018, 7:15pm UTC](https://discourse.processing.org/t/solved-typeerror-xml-getchildren-is-not-a-function/1697/2 "2018-07-11T19:15:16Z")

</div>

[https://p5js.org/reference/#/p5/preload](https://p5js.org/reference/#/p5/preload)  
[https://p5js.org/reference/#/p5/loadXML](https://p5js.org/reference/#/p5/loadXML)

---

<div class="post-metadata">

**Author:** ![T\_mex](https://avatars.discourse-cdn.com/v4/letter/t/74df32/32.png) [@T\_mex](https://discourse.processing.org/u/T_mex)\
**Post date:** [July 11, 2018, 7:19pm UTC](https://discourse.processing.org/t/solved-typeerror-xml-getchildren-is-not-a-function/1697/3 "2018-07-11T19:19:19Z")

</div>

_ **edit:** _ added the parseXML to a class

I have read and included both of the above.

I’m still seeing the same error message.

```auto
var xmlFile;
var obj_UserData;
function preload(){
 	xmlFile = new XML();
 	xmlFile = loadXML("XML/UserInfo.xml");
}
function setup(){
	createCanvas(windowWidth,windowHeight);
       obj_UserData = new obj_UserData();
       obj_UserData.parseXML();
}
class UserData{
    function parseXML(){
	    print(xmlFile.getChildren('User'));	
    }
}

```

The error I’m still getting is “TypeError: xmlFile.getChildren is not a function”

---

<div class="post-metadata">

**Author:** ![T\_mex](https://avatars.discourse-cdn.com/v4/letter/t/74df32/32.png) [@T\_mex](https://discourse.processing.org/u/T_mex)\
**Post date:** [July 11, 2018, 7:35pm UTC](https://discourse.processing.org/t/solved-typeerror-xml-getchildren-is-not-a-function/1697/4 "2018-07-11T19:35:54Z")

</div>

**Solved**

I forgot I needed to hand over the info to the constructor.

```auto
var xmlFile;
var obj_UserData;
function preload(){
	xmlFile = loadXML("XML/Data.xml");
}
function setup(){
 obj_UserData = new DataHolder(xmlFile);
 obj_UserData.ReadXml();
}
class UserData{
	constructor(_xml){
            this.xml = _xml;
        }
        ReadXml(){
		print(this.XML.getChildren('User'));
	}
}

```
