3
Contributors
9
Replies
39
Views
2 Years
Discussion Span
Last Post by Eirik
0

Here's a start...

<?php
$dom = new DOMDocument();
$dom->load('cerdi.xml');
$dcs = $dom->getElementsByTagName('dc');
foreach ($dcs as $dc) {

I managed to get it to work. As rubberman says, show some effort and we'll help you along.

0

This is new for me so I need help to complete this task. Will u help me to get a working example?

0

This is new for me so I need help to complete this task. Will u help me to get a working example?

Well, I've given you a heads up with regard to DOMDocument. Alternatively you could use SImpleXML or a number of other libraries/classes. You just need an XML parser.

I managed it in 12 lines of code, so it's not that difficult. Have a search for "XML parsing in PHP" or "XML reader PHP". If you are serious about programming, then this kind of research will be your bread and butter for the next few years. If you refuse to help yourself at this early stage, then programming is not for you.

0

Great. Post your code here so it may be of use to others. Also mark as solved :)

1

Great stuff. Here's mine:

<style>
    dt{
        text-transform: capitalize;
        font-weight: bold;
    }
</style>
<?php
$dom = new DOMDocument();
$dom->load('cerdi.xml');
$dcs = $dom->getElementsByTagName('dc');
$data = '';
foreach ($dcs as $dc) {
    $data .= "<dl>";
    foreach ($dc->childNodes as $i) {
        if(!$i->localName) continue;
        $dt = ($f = $i->getAttribute('id')) ? $f : $i->localName;
        $data .= "<dt>$dt</dt><dd>{$i->nodeValue}</dd>";
    }
    $data .= "</dl><hr />";
}

echo $data;
0

So how would you get the value of: <dc:identifier id="localid">261117</dc:identifier> ? I tried with $xpath->query( '//identifier[@id="localid"]' )->item(0)->nodeValue; without luck...

Edited by Eirik

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.