Can anyone help me with how I can retrive the data of this XML with PHP i need to echo the <dc> data ex. <dc:title> and so on.
XML file: http://askbib.asker.folkebibl.no/cgi-bin/sru?operation=searchRetrieve&version=1.2&query=rec.identifier=%22261118%22&recordSchema=dc&startRecord=1&maximumRecords=10

Make an effort to solve this, post your PHP code here, and then we may be able to help.

Member Avatar for diafol

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.

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

Member Avatar for diafol

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.

I got it to work. Thanks forbhelping.

Member Avatar for diafol

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

Member Avatar for diafol

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;

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...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.