My xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<root>
<item>
<Post>
<id><![CDATA[1]]></id>
<title><![CDATA[The title]]></title>
<body><![CDATA[This is the post body.]]></body>
<created><![CDATA[2008-07-28 12:01:06]]></created>
<modified><![CDATA[]]></modified>
</Post>
</item>
<item>
<Post>
<id><![CDATA[2]]></id>
<title><![CDATA[A title once again]]></title>
<body><![CDATA[And the post body follows.]]></body>
<created><![CDATA[2008-07-28 12:01:06]]></created>
<modified><![CDATA[]]></modified>
<item>
<item><![CDATA[fdgs]]></item>
</item>
</Post>
</item>
<item>
<Post>
<id><![CDATA[3]]></id>
<title><![CDATA[Title strikes back]]></title>
<body><![CDATA[This is really exciting Not.]]></body>
<created><![CDATA[2008-07-28 12:01:06]]></created>
<modified><![CDATA[]]></modified>
</Post>
</item>
</root>
Here is the my expected output:
Array(
0=>Array(
'Post'=>Array(
'id'=>1,
'title'=>'The title',
'body'=>'This is the post body.',
'created'=>'2008-07-28 12:01:06',
'modified'=>'',)
),
1=>Array(
'Post'=>Array(
'id'=>2,
'title'=>'A title once again',
'body'=>'And the post body follows.',
'created'=>'2008-07-28 12:01:06',
'modified'=>'',
array('fdgs'),)
),
2=>Array(
'Post'=>Array(
'id'=>3,
'title'=>'Title strikes back',
'body'=>'This is really exciting Not.',
'created'=>'2008-07-28 12:01:06',
'modified'=>'',)
),
);
And this is my code:
$xml=new Xml2Array();
$xmlData = simplexml_load_file('d:\\xmlfile\\Array2XmlExampleData.xml');
$expectedResult=$xml->simpleXMLToArray($xmlData);
var_dump($expectedResult);
The array result I get from var_dump() is null. How can I solve this problem? Please help me out, thanks.