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

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

 	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.

https://p5js.org/reference/#/p5/preload
https://p5js.org/reference/#/p5/loadXML

edit: added the parseXML to a class

I have read and included both of the above.

I’m still seeing the same error message.

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”

Solved

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

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'));
	}
}
1 Like