lindm Posted October 8, 2008 Share Posted October 8, 2008 Just new to XML parsing but can't seem to get my xml file to work. Please see code below. Two questions: 1. Is the colon a problem? 2. How can I print only the tag where contextRef="DURcy" <?php $string='<?xml version="1.0" encoding="UTF-8"?> <xbrli:xbrl> <se-gen-base:Inledning contextRef="DURcy">10000</se-gen-base:Inledning> <se-gen-base:Inledning contextRef="DURpy">20000</se-gen-base:Inledning> </xbrli:xbrl> ' ; $xml = simplexml_load_string($string); print header("Content-type: text/plain"); print_r($xml->xpath("/xbrli:xbrl/se-gen-base:Inledning")); ?> Link to comment https://forums.phpfreaks.com/topic/127609-solved-xml-parsing/ Share on other sites More sharing options...
R0bb0b Posted October 8, 2008 Share Posted October 8, 2008 You would probably benefit from reading up on working with strings in php: here is the manual http://us3.php.net/types.string Link to comment https://forums.phpfreaks.com/topic/127609-solved-xml-parsing/#findComment-660263 Share on other sites More sharing options...
lindm Posted October 10, 2008 Author Share Posted October 10, 2008 Now I am really close: $string=<<<XML <?xml version="1.0" encoding="UTF-8"?> <xbrli xmlns:se-gen-base="xxxxx" > <se-gen-base:Inledning contextRef="DURcy">10000</se-gen-base:Inledning> <se-gen-base:Inledning contextRef="DURpy">20000</se-gen-base:Inledning> </xbrli> XML; $xml = simplexml_load_string($string); foreach ($xml->children('xxxxx')->Inledning as $test) { if ((string)$test['contextRef'] == 'DURcy') echo $test; } Why doesn't this return 10000? Link to comment https://forums.phpfreaks.com/topic/127609-solved-xml-parsing/#findComment-662306 Share on other sites More sharing options...
lindm Posted October 11, 2008 Author Share Posted October 11, 2008 This seems to work $xml = simplexml_load_string($string); foreach ($xml->children('xxxxx')->Inledning as $test) { if ((string)$test->attributes()->contextRef == 'DURpy') echo $test; } Link to comment https://forums.phpfreaks.com/topic/127609-solved-xml-parsing/#findComment-662679 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.