Hi, I’m trying to load a xml file only if he’s correct (no tags errors)
I’have try this
void checkXml(String fileName) {
try {
data = loadXML(fileName);
}
catch(Exception e) {
print(e);
}
}
I put just one error in the xml file and my program blocks.
How can I check if my xml file is correct and after use it or not
1 Like
Your problem is that you need an XML object. One approach: Your function will try to get one from loadXML, but if it fails (and you want to continue) then you set your return to null, AND THEN CHECK if your object is null. Here is one example, demonstrated using a local rather than a global variable:
void setup() {
XML f = checkXML("foo.xml");
rect(5, 5, 85, 85);
fill(0);
if(f != null){
text("loaded", 10, 20);
} else {
text("not loaded", 10, 20);
}
}
XML checkXML(String fileName) {
try {
return loadXML(fileName);
}
catch(Exception e) {
print(e);
}
return null;
}