I have an m-file that reads an XML file to get inputs. I'm running into a problem with comments in the XML file. Simply put, if I put a comment inside the tag but before the value, then I get an empty string for the value. Comments elsewhere don't cause problems
Here's a toy example of my m-file:
function userInputStruct = readToyXmlInput()
toyXmlInputFile = 'toyXmlInput.xml';
xDoc = xmlread(toyXmlInputFile);
userInput = xDoc.getElementsByTagName('userInput');
userInputStruct = struct();
thisUserInput = userInput.item(0);
thisInput_01 = thisUserInput.getElementsByTagName('input_01');
thisInput_01Element = thisInput_01.item(0);
temp01 = thisInput_01Element.getFirstChild.getData;
input_01 = strip(temp02);
userInputStruct.input_01 = input_01;
Here's a toy example of my XML file:
<!-- A comment here is fine. -->
Dummy input #1 <!-- A comment here is fine. -->
<!-- A comment here is fine. -->
Here's a toy example of my XML file with a comment that causes a problem.
<!-- A comment here causes problems -->
What am I doing wrong? What can I do differently so that comments after the tag but before the value don't cause problems?
Worst-case, I'll just document in the m-file and the XML file that there's a limit on where comments can go. However, I'd prefer a more elegant solution.