login  Naam:   Wachtwoord: 
Registreer je!
 Forum

Uitlezen van XML bestand loopt vast op de laatste node (Opgelost)

Offline Jurgo - 12/03/2010 12:09 (laatste wijziging 12/03/2010 15:14)
Avatar van JurgoPHP 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:
  1. <?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/">
  2. <ns2:serverInfo protocol="SRW/U">
  3. </ns2:serverInfo>
  4. <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
  5. bibliographies.
  6. </ns2:description><ns2:author>Luci&#xEB;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">
  7. <ns2:title>OCLC Research SRW Server version 1.1</ns2:title>
  8.  
  9. </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">
  10. <ns2:title>Any</ns2:title>
  11. <ns2:map>
  12. <ns2:name set="cql">serverChoice</ns2:name>
  13.  
  14. </ns2:map>
  15. </ns2:index><ns2:index scan="false" search="true" sort="false">
  16.  
  17. <ns2:title>Identifier</ns2:title>
  18. <ns2:map>
  19. <ns2:name set="dc">identifier</ns2:name>
  20. </ns2:map>
  21. <ns2:map>
  22. <ns2:name set="marc">001</ns2:name>
  23. </ns2:map>
  24.  
  25. <ns2:map>
  26. <ns2:name set="ead">unitid</ns2:name>
  27.  
  28. </ns2:map>
  29.  
  30. <ns2:map>
  31. <ns2:name set="iisg">identifier</ns2:name>
  32. </ns2:map>
  33. <ns2:map>
  34. <ns2:name set="ead">eadid</ns2:name>
  35.  
  36.  
  37. </ns2:map>
  38. </ns2:index>


De volgende PHP code heb ik gebruikt:


  1. $xml = file_get_contents("link naar XML-document");
  2. $xml = str_replace("ns2:", "", $xml);
  3. $xml = simplexml_load_string($xml);
  4.  
  5. foreach($xml->record->recordData->explain->indexInfo->index as $index)
  6. {
  7. echo $index->title;
  8. foreach($index->title as $title)
  9. {
  10. foreach($title->map as $map)
  11. {
  12. foreach($map->name as $name)
  13. {
  14. echo $name->firstChild->nodeValue;
  15. }
  16. }
  17. }
  18. }


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:
  1. $xml = file_get_contents("http://api.iisg.nl/solr/all/srw");
  2. $xml = str_replace("ns2:", "", $xml);
  3. $xml = simplexml_load_string($xml);
  4.  
  5. foreach($xml->record->recordData->explain->indexInfo->index as $index)
  6. {
  7. foreach($index->title as $title)
  8. {
  9. echo $index->title;
  10. }
  11.  
  12. foreach($index->map as $map)
  13. {
  14. foreach($map->children() as $name)
  15. {
  16. echo $name;
  17. }
  18. }
  19. }


Ik heb het voor elkaar gekregen het laatste stukje code is veranderd naar:
  1. foreach($map->children() as $name)
  2. {
  3. $at = $name['set'];
  4.  
  5. if(strpos($at->asXML(), 'marc') !== false)
  6. {
  7. echo $name;
  8. }
  9. }

0 antwoorden

Gesponsorde links
Er zijn nog geen reacties op dit bericht.
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.201s