How to get Matlab to read correct amount of xml nodes

Viewed 12993

I'm reading a simple xml file using matlab's xmlread internal function.

<root>
    <ref>
        <requestor>John Doe</requestor>
        <project>X</project>
    </ref>
</root>

But when I call getChildren() of the ref element, it's telling me that it has 5 children.

It works fine IF I put all the XML in ONE line. Matlab tells me that ref element has 2 children.

It doesn't seem to like the spaces between elements.

Even if I run Canonicalize in oXygen XML editor, I still get the same results. Because Canonicalize still leaves spaces.

Matlab uses java and xerces for xml stuff.

Question:

What can I do so that I can keep my xml file in human readable format (not all in one line) but still have matlab correctly parse it?

Code Update:

filename='example01.xml';
docNode = xmlread(filename);
rootNode = docNode.getDocumentElement;
entries = rootNode.getChildNodes;
nEnt = entries.getLength
2 Answers
Related