Safe parsing of innerData in Haxe.xml.Fast with empty content



I'm having a hard time, reading innerData, when parsing an xml in haxe, using haxe.xml.Fast.


I'm trying to use these utility functions in a custom Class named XMLUtil



public static function getNodeNamed(parent:Fast, nodeName:String):Fast {
if ( parent.hasNode.resolve(nodeName)) {
return parent.node.resolve(nodeName);
}else {
return null;
}
}

public static function getNodeText(parent:Fast, nodeName:String):String {
var node : Fast = getNodeNamed(parent, nodeName);

try {
return node.innerData.toString(); // Still crashing here, although it's in a try-catch block
}catch (err:Error) {
return "";
}
return null;
}


When I'm parsing a node that don't necessarily have inner data (see 'triggers' node)



<dialog id="tut4_2" repeat="2">
<text>Blah blah blah</text>
<triggers></triggers>
<triggered>tut4_1</triggered>
</dialog>


I'm getting a crash when accessing the node's innerData



var triggers:String = XMLUtil.getNodeText(newDialog, "triggers");


Here's the runtime error




[Fault] exception, information=triggers does not have data
Fault, get_innerData() at Fast.hx:140


The weirdest thing that I really don't get, is that i'm calling the innerData in a try-catch block, but I'm still having my function crashing.


Why is this happening, and how can I access the innerData in a safe and convenient way?


I'm using Haxe 3.1.3 and NME 3.0


P.S I know that Fast is meant to be used with a stricter XML structure, but I'm porting a large XML files collection from an as3 project, and I don't want to change the XML content. I just want to deal with it programmatically.


No comments:

Post a Comment