Struggling with XML of all things


I’m new to the world of HAXE and OpenFL My company asked me to look in to it as a means for broadening what we can do, and I don’t want to let them down as this appears to be a very promising tool. Until now I’ve mostly worked in HTML5, CSS, and AS3.

So my problem is that I’ve been trying to import an external XML file called cards.xml. I manged to get it imported, however when I trace out the data I get gibberish like this:

Main.hx:34: {
nodeType : 6, 
children : [{
		nodeType : 5, 
		children : [], 
		attributeMap : {
			h : {

		nodeValue : xml version="1.0" encoding="utf-8" , 
		parent : {
			nodeType : 6, 
			children : [<...>,<...>,<...>], 
			attributeMap : {
				h : <...>

By gibberish I mean stuff that isn’t useful for display. So I attempted to parse the data, and this is where I am struggling. My structure should look like this:

  <card id="1">

With multiple card nodes following the above.

Can somebody point me to a guide on XML and how to interact with nodes and children? All my attempts produce little results and many errors. As it is I’ve found very few resources on this subject aside from creating XML (which I do not wish to do). I simply want to be able to target my nodes and loop through them.

Any help will be appreciated.

Hello! You probably are looking for the haxe.xml.Fast API (which in Haxe 4 previews is named haxe.xml.Access instead)

Although it is not a full E4X XML implementation, it has been more than enough for my needs

Here’s an example based on the Haxe documentation and W3Schools:


<?xml version="1.0" encoding="UTF-8"?>
<note id="100">
  <body>Don't forget me this weekend!</body>


import haxe.xml.Fast;
import openfl.utils.Assets;


var data = Xml.parse (Assets.getText ("assets/note.xml"));
var xml = new Fast (data.firstElement ());

var id = ( ? : 0);
var to =;
var from = xml.node.from.innerData;
var heading = (xml.hasNode.heading ? xml.node.heading.innerData : "");
var body = xml.node.body.innerData;

trace (id, to, from, heading, body);

You might also want innerHTML instead of innerData.

Thanks for the reply!

I plugged the fields for my XML into what you provided, but I’m getting an odd error with this line:

var id = ( ? : 0);

My XML is similar in structure to yours:

<card id="001">
    <artist>Grant Wood</artist>
    <title>American Gothic</title>

So I do not see why it would give me this error message:

src/Main.hx:33: characters 38-39 : Int should be String

It’s clearly seeing the id value as a String “001” rather than the integer 1. I’ve tried to convert it (such as with Number() ), but HaxeDevelop keeps telling me those methods don’t work: Unknown Identifier : Number.

Any thoughts? And Thanks again!


std.parseInt() Is what I needed. I was having trouble finding that, but find it I did.

Thanks again!

Oops! Sorry, that was an issue with my code. It should have been "0" as a default value, or like you said, Std.parseInt or Std.parseFloat depending on the data type.

I usually don’t do it as a one-liner like that, but I wanted to help show that has is a valuable way to check if an attribute exists, which is super-common :slight_smile: