my xml look like this:--->
<?xml version="1.0"?>
<childrens>
<child1 entity_id="1" value="Root Catalog" parent_id="0">
<child2 entity_id="2" value="Navigate" parent_id="1">
<child4 entity_id="4" value="Activities" parent_id="2">
</child4>
</child2>
</child1>
</childrens>
i want out put something like this:--->
Root Catalog
Navigate
Activities
this is my code:
<?php
$str = '<childrens>
<child1 entity_id="1" value="Root Catalog" parent_id="0">
<child2 entity_id="2" value="Navigate" parent_id="1">
<child4 entity_id="4" value="Activities" parent_id="2">
</child4>
</child2>
</child1>
</childrens>';
$pattern = '/<(.*)="(.*)">/';
preg_match_all($pattern, $str, $matches);
print_r($matches[1]);
?>
How's this:
<?php
$str = '<childrens>
<child1 entity_id="1" value="Root Catalog" parent_id="0">
<child2 entity_id="2" value="Navigate" parent_id="1">
<child4 entity_id="4" value="Activities" parent_id="2">
</child4>
</child2>
</child1>
</childrens>';
$xml = simplexml_load_string($str);
$values = $xml->xpath('//@value');
foreach($values as $value) {
echo $value."
";
}
?>
Its been ages since i have used jquery but if you have, then i think a crude code to get values might be
var selected = $('*[value]'),res =[];
for(var i =0;i<selected.length; i++) {
res.push(selected[i].value);
}
i am sure you can use a .each with some function to do this in one line, I am just too rusted with jquery to give you that answer
If You have xml file saperated..
<script>
$(document).ready(function()
{
var html = '';
$.get('my.xml', function(d){
$(d).find('children').each(function(){
$(this).children().each(getChildNode);
});
console.log(html);
alert(html);
});
function getChildNode(obj){
html += $(this).attr('value') + '
<br>';
if($(this).children().length > 0){
$(this).children().each(getChildNode);
}
}
});
</script>
I hope it will work for you.
thanks