I have to parse a xml data I am using simplexml following is the simple xml object i got
SimpleXMLElement Object
(
[@attributes] => Array
(
[version] => 1.2
)
[file] => SimpleXMLElement Object
(
[@attributes] => Array
(
[source-language] => en
[datatype] => plaintext
[original] => file.ext
)
[body] => SimpleXMLElement Object
(
[trans-unit] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 1
)
[source] => search_term
[target] => %count% result for "%query%" has been found.|%count% results for "%query%" have been found.
[alt-trans] => SimpleXMLElement Object
(
[target] => Hola mundo
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 2
)
[source] => search_noresults
[target] => Sorry, I found no results for your query on the website.
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 3
)
[source] => search_failure
[target] => We are very sorry, but the search service is not available at the moment.
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 4
)
[source] => search
[target] => Search
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 5
)
[source] => previous
[target] => Prev
)
[5] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 6
)
[source] => next
[target] => Next
)
[6] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 7
)
[source] => Search this site
[target] => Search this site
)
[7] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 8
)
[source] => send
[target] => Send
)
)
)
)
)
Problem arise when i try to parse the data by following code
$this->glossary = new SimpleXMLElement($this->text);
foreach($this->glossary->file->body->trans-unit as $transunit)
{
//parsing code
}
i get a php error as variable cannot have "-" in between and we have trans-unit as a object variable.We cannot change xml file as it is in the predefined format.
I have another question regarding simplexml i have the following xml unit
<trans-unit id="1">
<source>search_term</source>
<target>%count% result for "%query%" has been found.|%count% results for "%query%" have been found.</target>
<alt-trans>
<target xml:lang='es'>Hola mundo</target>
</alt-trans>
</trans-unit>
i want to extract the "lang='es'" namespace from <alt-trans> tag in the foreach loop the defined above.