Jump to content

[SOLVED] XML parsing


lindm

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.