Here is an XML file I'm trying to parse with MXML library:
<?xml version="1.0" encoding="utf-8"?>
<msg xmlns="http://uri.etsi.org/ori/002-2/v1.1.1">
<header>
<msgType>REQ</msgType>
<msgUID>4567</msgUID>
</header>
<body>
<updateSwPrepReq>
<ftpSrvIpAddress>192.168.1.1</ftpSrvIpAddress>
<ftpSrvUserName>SW_User</ftpSrvUserName>
<ftpSrvPassword></ftpSrvPassword>
<ftpSrvSwPkgDirPath>/swImages/acme</ftpSrvSwPkgDirPath>
<SwUpgradePkgVer>RAN-201204-008</SwUpgradePkgVer>
</updateSwPrepReq>
</body>
</msg>
I can parse and get the element name ('msgTyp'e, 'msgUID'), but not the associated values ('REQ', '4567').
Here is a part of my code:
mxml_node_t *tree = NULL;
mxml_node_t *node = NULL;
mxml_node_t *node_tmp = NULL;
tree = mxmlLoadFile(NULL, "Test.xml", MXML_TEXT_CALLBACK);
node = mxmlFindElement(tree, tree, "msg", NULL, NULL, MXML_DESCEND);
tmp = mxmlElementGetAttr(node, "xmlns");
printf("msg attribut : %s \n", tmp);
node_tmp = mxmlFindElement(tree, tree, "msgType", NULL, NULL, MXML_DESCEND);
if (node_tmp != NULL)
{
printf("node_tmp not null");
printf("msgType : %s", node_tmp->child->value.text.string);
}
node_tmp is not NULL because the first printf works. But I get a segmentation fault (core dumped) error.
Can anyone help me? Thanks in advance
EDIT : I found the solution (it works in my case...). Hope it can help...
Just open the file with this command:
tree = mxmlLoadFile(NULL, "Test.xml", MXML_OPAQUE_CALLBACK);
And get the value with this one:
printf("msgType : %s", node_tmp->child->value.opaque);