PHP interesse |
|
Hallo allemaal,
Ik wil graag een XML bestand uitlezen en dit lukt ook tot op een zekere hoogte.
De volgende node krijg ik niet uitgelezen: <ns2:name set="marc">001</ns2:name>
Dit omdat hier set="marc" instaat lukt het niet om deze aan te spreken.
Voor de rest kan ik wel alle elementen aanspreken en uitlezen.
Een gedeelte van het XML document ziet er als volgt uit:
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet title="OCLC XSL formatting" type="text/xsl" href="?resource=explainResponse.xsl"?><explainResponse xmlns="http://www.loc.gov/zing/srw/"><version>1.1</version><record xmlns:ns1="http://www.loc.gov/zing/srw/"><recordSchema>http://explain.z3950.org/dtd/2.0/</recordSchema><recordPacking>xml</recordPacking><recordData><ns2:explain authoritative="true" xmlns="http://explain.z3950.org/dtd/2.0/" xmlns:ns2="http://explain.z3950.org/dtd/2.0/">
<ns2:serverInfo protocol="SRW/U">
</ns2:serverInfo>
<ns2:databaseInfo><ns2:title>IISH datasets and bibliographical records</ns2:title><ns2:description>The api will give you descriptive information on IISH research data, images, archives and
bibliographies.
</ns2:description><ns2:author>Luciën van Wouw</ns2:author><ns2:contact>lwo@iisg.nl</ns2:contact><ns2:restrictions>Copyright 2010 International Institute for Social History, The Netherlands.</ns2:restrictions><ns2:implementation identifier="http://www.oclc.org/research/software/srw" version="1.1">
<ns2:title>OCLC Research SRW Server version 1.1</ns2:title>
</ns2:implementation></ns2:databaseInfo><ns2:metaInfo><ns2:dateModified>metaInfo.dateModified</ns2:dateModified><ns2:aggregatedFrom>metaInfo.aggregatedFrom</ns2:aggregatedFrom><ns2:dateAggregated>metaInfo.dateAggregated</ns2:dateAggregated></ns2:metaInfo><ns2:indexInfo><ns2:set identifier="info:srw/cql-context-set/1/cql-v1.1" name="cql"/><ns2:set identifier="info:srw/cql-context-set/1/dc-v1.1" name="dc"/><ns2:set identifier="info:srw/cql-context-set/1/marc-1.1" name="marc"/><ns2:set identifier="info:srw/cql-context-set/1/iisg-0.9" name="iisg"/><ns2:set identifier="info:srw/cql-context-set/1/ead-v2002" name="ead"/><ns2:set identifier="info:srw/cql-context-set/2/solr-2.2" name="solr"/><ns2:index scan="false" search="true" sort="false">
<ns2:title>Any</ns2:title>
<ns2:map>
<ns2:name set="cql">serverChoice</ns2:name>
</ns2:map>
</ns2:index><ns2:index scan="false" search="true" sort="false">
<ns2:title>Identifier</ns2:title>
<ns2:map>
<ns2:name set="dc">identifier</ns2:name>
</ns2:map>
<ns2:map>
<ns2:name set="marc">001</ns2:name>
</ns2:map>
<ns2:map>
<ns2:name set="ead">unitid</ns2:name>
</ns2:map>
<ns2:map>
<ns2:name set="iisg">identifier</ns2:name>
</ns2:map>
<ns2:map>
<ns2:name set="ead">eadid</ns2:name>
</ns2:map>
</ns2:index>
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet title="OCLC XSL formatting" type="text/xsl" href="?resource=explainResponse.xsl"?><explainResponse xmlns="http://www.loc.gov/zing/srw/"><version>1.1</version><record xmlns:ns1="http://www.loc.gov/zing/srw/"><recordSchema>http://explain.z3950.org/dtd/2.0/</recordSchema><recordPacking>xml</recordPacking><recordData><ns2:explain authoritative="true" xmlns="http://explain.z3950.org/dtd/2.0/" xmlns:ns2="http://explain.z3950.org/dtd/2.0/"> <ns2:serverInfo protocol="SRW/U"> </ns2:serverInfo> <ns2:databaseInfo><ns2:title>IISH datasets and bibliographical records</ns2:title><ns2:description>The api will give you descriptive information on IISH research data, images, archives and bibliographies. </ns2:description><ns2:author>Luciën van Wouw</ns2:author><ns2:contact>lwo@iisg.nl</ns2:contact><ns2:restrictions>Copyright 2010 International Institute for Social History, The Netherlands.</ns2:restrictions><ns2:implementation identifier="http://www.oclc.org/research/software/srw" version="1.1"> <ns2:title>OCLC Research SRW Server version 1.1</ns2:title> </ns2:implementation></ns2:databaseInfo><ns2:metaInfo><ns2:dateModified>metaInfo.dateModified</ns2:dateModified><ns2:aggregatedFrom>metaInfo.aggregatedFrom</ns2:aggregatedFrom><ns2:dateAggregated>metaInfo.dateAggregated</ns2:dateAggregated></ns2:metaInfo><ns2:indexInfo><ns2:set identifier="info:srw/cql-context-set/1/cql-v1.1" name="cql"/><ns2:set identifier="info:srw/cql-context-set/1/dc-v1.1" name="dc"/><ns2:set identifier="info:srw/cql-context-set/1/marc-1.1" name="marc"/><ns2:set identifier="info:srw/cql-context-set/1/iisg-0.9" name="iisg"/><ns2:set identifier="info:srw/cql-context-set/1/ead-v2002" name="ead"/><ns2:set identifier="info:srw/cql-context-set/2/solr-2.2" name="solr"/><ns2:index scan="false" search="true" sort="false"> <ns2:title>Any</ns2:title> <ns2:map> <ns2:name set="cql">serverChoice</ns2:name> </ns2:map> </ns2:index><ns2:index scan="false" search="true" sort="false"> <ns2:title>Identifier</ns2:title> <ns2:map> <ns2:name set="dc">identifier</ns2:name> </ns2:map> <ns2:map> <ns2:name set="marc">001</ns2:name> </ns2:map> <ns2:map> <ns2:name set="ead">unitid</ns2:name> </ns2:map> <ns2:map> <ns2:name set="iisg">identifier</ns2:name> </ns2:map> <ns2:map> <ns2:name set="ead">eadid</ns2:name> </ns2:map> </ns2:index>
De volgende PHP code heb ik gebruikt:
$xml = file_get_contents("link naar XML-document");
$xml = str_replace("ns2:", "", $xml);
$xml = simplexml_load_string($xml);
foreach($xml->record->recordData->explain->indexInfo->index as $index)
{
echo $index->title;
foreach($index->title as $title)
{
foreach($title->map as $map)
{
foreach($map->name as $name)
{
echo $name->firstChild->nodeValue;
}
}
}
}
$xml = simplexml_load_string($xml); foreach($xml->record->recordData->explain->indexInfo->index as $index) { foreach($index->title as $title) { foreach($title->map as $map) { foreach($map->name as $name) { echo $name->firstChild->nodeValue; } } } }
Ik hoop dat iemand mij kan helpen bij het uitlezen van deze laatste node!
UPDATE !!!
Na het wijzigen van mijn PHP code kan ik de nodes wel uitlezen. Nu wil ik echter alleen de nodes uitlezen waarvan de naam: "name set='marc'" is.
Mijn PHP code is nu:
$xml = file_get_contents("http://api.iisg.nl/solr/all/srw");
$xml = str_replace("ns2:", "", $xml);
$xml = simplexml_load_string($xml);
foreach($xml->record->recordData->explain->indexInfo->index as $index)
{
foreach($index->title as $title)
{
echo $index->title;
}
foreach($index->map as $map)
{
foreach($map->children() as $name)
{
echo $name;
}
}
}
$xml = simplexml_load_string($xml); foreach($xml->record->recordData->explain->indexInfo->index as $index) { foreach($index->title as $title) { } foreach($index->map as $map) { foreach($map->children() as $name) { } } }
Ik heb het voor elkaar gekregen het laatste stukje code is veranderd naar:
foreach($map->children() as $name)
{
$at = $name['set'];
if(strpos($at->asXML(), 'marc') !== false)
{
echo $name;
}
}
foreach($map->children() as $name) { $at = $name['set']; if(strpos($at->asXML(), 'marc') !== false) { } }
|