SimpleXML node parse Lyric Wikia REST API - php

Taken from the Lyrics Wikia REST api XML response http://api.wikia.com/wiki/LyricWiki_API/REST , how do I parse this? I wasn't able to find any examples of other people working with these nodes.
http://lyrics.wikia.com/api.php?func=getArtist&artist=Linkin_Park&fmt=xml
<getArtistResponse>
<artist>Linkin Park</artist>
<albums>
<album>Xero</album>
<year>1997</year>
<amazonLink>
http://www.amazon.com/exec/obidos/redirect?link_code=ur2&tag=wikia-20&camp=1789&creative=9325&path=external-search%3Fsearch-type=ss%26index=music%26keyword=Linkin%20Park%20Xero
</amazonLink>
<songs>
<item>Rhinestone</item>
<item>Reading My Eyes</item>
<item>Fuse</item>
<item>Stick N' Move</item>
</songs>
<album>Hybrid Theory</album>
<year>1999</year>
<amazonLink>
http://www.amazon.com/exec/obidos/redirect?link_code=ur2&tag=wikia-20&camp=1789&creative=9325&path=external-search%3Fsearch-type=ss%26index=music%26keyword=Linkin%20Park%20Hybrid%20Theory
</amazonLink>
<songs>
<item>Carousel</item>
<item>Technique</item>
<item>Step Up</item>
<item>And One</item>
<item>High Voltage (EP Version)</item>
<item>Part Of Me</item>
<item>High Voltage</item>
<item>Esaul (Underground EP)</item>
</songs>
<album>Hybrid Theory</album>
<year>2000</year>
<amazonLink>
http://www.amazon.com/exec/obidos/redirect?link_code=ur2&tag=wikia-20&camp=1789&creative=9325&path=external-search%3Fsearch-type=ss%26index=music%26keyword=Linkin%20Park%20Hybrid%20Theory
</amazonLink>
<songs>
<item>Papercut</item>
<item>One Step Closer</item>
<item>With You</item>
<item>Points Of Authority</item>
<item>Crawling</item>
<item>Runaway</item>
<item>By Myself</item>
<item>In The End</item>
<item>A Place For My Head</item>
<item>Forgotten</item>
<item>Cure For The Itch</item>
<item>Pushing Me Away</item>
<item>My December</item>
<item>High Voltage</item>
<item>Papercut</item>
<item>Papercut</item>
<item>Points Of Authority</item>
<item>A Place For My Head</item>
</songs>
I'd like for these to look like the following with links to each song node:
Xero 1997: Rhinestone Reading My Eyes Fuse Stick N' Move
Hybrid Theory 1999: Carousel Technique Step Up Etc..
I've been able to get the song->items with `
foreach ($xml->albums->songs as $entry){
$item0 = $entry->item[0];
$item1 = $entry->item[1];
$item2 = $entry->item[2];
$item3 = $entry->item[3];
$item4 = $entry->item[4];
etc
But I have been unsuccessful in grabbing each album and year beyond the first.
Thank you for the help. :)

Related

PHP Soap Client request answers with a single String

I'm a bit of an noob when it comes to SOAP client requests.
I'm hoping someone could help, I'm trying to make a soap client request to a website. I can make the request however the returned XML (which I'm turning into an Array) seems to come as a single string not separated into the XML elements.
The XML:
<ProductList>
<Product>
<ProductCode>00380</ProductCode>
<ProductName>Droopy Eye Specs</ProductName>
<BrochureDescription>Droopy Eye Specs, Black, with Metal Spring, on Display Card</BrochureDescription>
<WebDescription>Droopy Eye Specs, Black, with Metal Spring</WebDescription>
<WashingInstructions>Not Applicable</WashingInstructions>
<RRP>1.8900</RRP>
<StockQuantity>943</StockQuantity>
<VatRate>20.00</VatRate>
<Gender>UNISEX</Gender>
<PackType>on Display Card</PackType>
<PackQty>1</PackQty>
<Audience>ADULT</Audience>
<Colour>BLACK</Colour>
<ETA>2019-07-04 00:00:00.</ETA>
<CataloguePage>641</CataloguePage>
<BarCode>5020570003800</BarCode>
<Price1>0.91</Price1>
<Price2>0.00</Price2>
<Price3>0.00</Price3>
<Break1>1.00</Break1>
<Break2>0.00</Break2>
<Break3>0.00</Break3>
<unit_size>1</unit_size>
<warnings/>
<carton>120</carton>
<stdPrice1>0.91</stdPrice1>
<stdPrice2>0.00</stdPrice2>
<stdPrice3>0.00</stdPrice3>
<stdBreak1>12.00</stdBreak1>
<stdBreak2>0.00</stdBreak2>
<stdBreak3>0.00</stdBreak3>
<Photo>1</Photo>
<CatalogueCode>JN-01</CatalogueCode>
<CatalogueName>Jokes & Novelties_Assorted</CatalogueName>
<Catalogue/>
<acc_code1>32928</acc_code1>
<acc_code2>32929</acc_code2>
<alt_code1>20073</alt_code1>
<alt_code2>25202</alt_code2>
<alt_code3>29111</alt_code3>
<alt_code4>6155</alt_code4>
<alt_code5>98413</alt_code5>
<new_code/>
<art_cat/>
<ImageAvailability>No</ImageAvailability>
<Seasonal>No</Seasonal>
<p_list2/>
<Licence_Territory/>
<ThemeName>Funnyside Fancy Dress</ThemeName>
<GroupID>3</GroupID>
<GroupName>Adult Fancy Dress Costumes</GroupName>
<GroupID1>0</GroupID1>
<ThemeGroup1>Uncategorized</ThemeGroup1>
<GroupID2>0</GroupID2>
<ThemeGroup2>Uncategorized</ThemeGroup2>
<GroupID3>0</GroupID3>
<ThemeGroup3>Uncategorized</ThemeGroup3>
<EFPrice>0.9100</EFPrice>
<EFQty>1</EFQty>
<size>Not Applicable</size>
<Ext_Size>NOT APPLICABLE</Ext_Size>
<GenericCode>00380</GenericCode>
<HasImageRights>No</HasImageRights>
<Safety>Warning! Not suitable for children under 3 years due to small parts. Choking Hazard.</Safety>
<Composition/>
</Product>
<Product>
<ProductCode>00429</ProductCode>
<ProductName>Metal Handcuffs</ProductName>
<BrochureDescription>Metal Handcuffs, Silver, with Key, on Display Card</BrochureDescription>
<WebDescription>Metal Handcuffs, Silver, with Key</WebDescription>
<WashingInstructions>Not Applicable</WashingInstructions>
<RRP>3.0900</RRP>
<StockQuantity>4926</StockQuantity>
<VatRate>20.00</VatRate>
<Gender>UNISEX</Gender>
<PackType>on Display Card</PackType>
<PackQty>1</PackQty>
<Audience>ADULT</Audience>
<Colour>SILVER</Colour>
<ETA>2019-02-10 00:00:00.</ETA>
<CataloguePage>424</CataloguePage>
<BarCode>5020570004296</BarCode>
<Price1>1.50</Price1>
<Price2>0.00</Price2>
<Price3>0.00</Price3>
<Break1>1.00</Break1>
<Break2>0.00</Break2>
<Break3>0.00</Break3>
<unit_size>1</unit_size>
<warnings>FREIG, FREIG,</warnings>
<carton>96</carton>
<stdPrice1>1.50</stdPrice1>
<stdPrice2>0.00</stdPrice2>
<stdPrice3>0.00</stdPrice3>
<stdBreak1>3.00</stdBreak1>
<stdBreak2>0.00</stdBreak2>
<stdBreak3>0.00</stdBreak3>
<Photo>1</Photo>
<CatalogueCode>AC-30</CatalogueCode>
<CatalogueName>Accessories_Truncheons & Handcuffs</CatalogueName>
<Catalogue/>
<acc_code1>29535</acc_code1>
<acc_code2>33723</acc_code2>
<acc_code3>96318</acc_code3>
<alt_code1>23076</alt_code1>
<alt_code2>23918</alt_code2>
<alt_code3>30652</alt_code3>
<alt_code4>34757</alt_code4>
<alt_code5>374</alt_code5>
<new_code/>
<art_cat/>
<ImageAvailability>No</ImageAvailability>
<Seasonal>No</Seasonal>
<p_list2/>
<Licence_Territory/>
<ThemeName>Cops & Robbers Fancy Dress</ThemeName>
<GroupID>3</GroupID>
<GroupName>Adult Fancy Dress Costumes</GroupName>
<GroupID1>0</GroupID1>
<ThemeGroup1>Uncategorized</ThemeGroup1>
<GroupID2>0</GroupID2>
<ThemeGroup2>Uncategorized</ThemeGroup2>
<GroupID3>0</GroupID3>
<ThemeGroup3>Uncategorized</ThemeGroup3>
<EFPrice>1.5000</EFPrice>
<EFQty>1</EFQty>
<size>Not Applicable</size>
<Ext_Size>NOT APPLICABLE</Ext_Size>
<GenericCode>00429</GenericCode>
<HasImageRights>No</HasImageRights>
<Safety>Warning! Not suitable for children under 3 years due to small parts - Choking Hazard. Keep these details for reference. Warning! Do not over tighten as this may cause the safety catch to jam. INSTRUCTIONS: 1. LOCK Move stop bar to upper position, press cuff down on wrist and rotate the jaw until it engages ratchet. Jaw may be tightened as required. Do not over tighten. Move stop bar to down position, jaw is thus locked against travel in either direction. 2. UNLOCK Move stop bar to open</Safety>
<Composition/>
</Product>
My PHP:
$apiKey = '00000';
$clientID = 'MyID';
$LanguageCode = 'EN';
$wdsl = 'http://webservices.website.com/services/products.asmx?WSDL';
$params = array('apiKey' => $apiKey, 'clientID' => $clientID);
$soapclient = new SoapClient($wdsl);
$response = $soapclient->GetFullDataSet($params);
$array = json_decode(json_encode($response), true);
print_r ($array);
the Returned Array :
Array ( [GetFullDataSetResult] => Array ( [any] => 00380Droopy Eye SpecsDroopy Eye Specs, Black, with Metal Spring, on Display CardDroopy Eye Specs, Black, with Metal SpringNot Applicable1.890094320.00UNISEXon Display Card1ADULTBLACK2019-07-04 00:00:00.64150205700038000.910.000.001.000.000.0011200.910.000.0012.000.000.001JN-01Jokes & Novelties_Assorted3292832929200732520229111615598413NoNoFunnyside Fancy Dress3Adult Fancy Dress Costumes0Uncategorized0Uncategorized0Uncategorized0.91001Not ApplicableNOT APPLICABLE00380NoWarning! Not suitable for children under 3 years due to small parts. Choking Hazard.00429Metal HandcuffsMetal Handcuffs, Silver, with Key, on Display CardMetal Handcuffs, Silver, with KeyNot Applicable3.0900492620.00UNISEXon Display Card1ADULTSILVER2019-02-10 00:00:00.42450205700042961.500.000.001.000.000.001FREIG, FREIG, 961.500.000.003.000.000.001AC-30Accessories_Truncheons & Handcuffs29535337239631823076239183065234757374NoNoCops & Robbers Fancy Dress3Adult Fancy Dress Costumes0Uncategorized0Uncategorized0Uncategorized1.50001Not ApplicableNOT APPLICABLE00429NoWarning! Not suitable for children under 3 years due to small parts - Choking Hazard. Keep these details for reference. Warning! Do not over tighten as this may cause the safety catch to jam. INSTRUCTIONS: 1. LOCK Move stop bar to upper position, press cuff down on wrist and rotate the jaw until it engages ratchet. Jaw may be tightened as required. Do not over tighten. Move stop bar to down position, jaw is thus locked against travel in either direction. 2. UNLOCK Move stop bar to open
How do I get the XML elements in to the Array as Each Element?
Eg. Product > Productcode > ProductName > BrochureDescription > Etc...
Let me know if there is any info I've missed out. Any Help would be appreciate.
Many thanks.

How to integrate xml hotel booking api using php

I am working for a project and I have to get data from a WSDL. This is my webservice url: http://203.109.97.241/axis/services/searchhoteldetails?wsdl. I've tried to integrate hotel booking xml api using php. I can get hotel result from with this code.
$xml_request = "<HotelSearchRequest>
<clientinfo>
<companycode>companycode</companycode>
<username>username</username>
<password>password</password> </clientinfo>
<hotelinfo>
<country>India</country>
<city>Goa</city>
<checkindate>20/04/2014</checkindate>
<checkoutdate>21/04/2014</checkoutdate>
<hotelname>thaj</hotelname>
<norooms>2</norooms>
<starrating/>
<roomtype/>
<responsetype>C</responsetype>
<roominginfo> </hotelinfo> </HotelSearchRequest>";
$client = new SoapClient("http://203.109.97.241/axis/services/searchhoteldetails?wsdl", array('soap_version' => SOAP_1_2));
$something = $client->getHotelDetailsXML($xml_request);
//var_dump($client->__getFunctions());
//var_dump($client->__getTypes());
var_dump($something);
print_r('<pre>');
print_r($something);
print_r('</pre>');
die();
?>
this is my output:1764 SRHOT7416 India Amla 30/08/2016 3 02/09/2016 2 0 HTRI143851 WebService Demo Webservice Hotel Group, has established four properties conveniently located in the commercial capital of India, Mumbai, since 1984.
These are fine. But my problem is how to echo only the country name from this result.
I'm not really sure what do you want to do... If you want to echo country name from the xml, you may want to use built-in SimpleXML parser.
I haven't used it, but this may be the solution.
Hope it works.

PHP: Read existing xml file and write new content

I have a .xsd-file and of course I can create a .xml-file from it. So basically I have a blank .xml-file (with no data/text)
With PHP I want to read the blank .xml-file, interate the nodes and fill them depending on the tag with data from the database.
There seem to be many options: XMLReader, XMLWriter, DOMDocument, SimpleXML
I don't know where to start. What would be the easies/leanest way?
More Information:
Here you kann find the .xsd-file...
The following .xml-file I created:
<?xml version="1.0" encoding="utf-8"?><Patienten>
<InfoXML>
<DatumXML></DatumXML>
<NameTudokusys></NameTudokusys>
<VersionTudokusys></VersionTudokusys>
</InfoXML>
<Patient>
<Stammdaten>
<PatientID></PatientID>
<GeburtsJahr></GeburtsJahr>
<GeburtsMonat></GeburtsMonat>
<GeburtsTag></GeburtsTag>
<Geschlecht></Geschlecht>
<EinwilligungTumordoku></EinwilligungTumordoku>
<EinwilligungExterneStelle></EinwilligungExterneStelle>
</Stammdaten>
<Fall>
<Anamnese>
<RelevanteKrebsvorerkrankungen></RelevanteKrebsvorerkrankungen>
<JahrRelevanteKrebsvorerkrankungen></JahrRelevanteKrebsvorerkrankungen>
<NichtRelevanteKrebsvorerkrankungen></NichtRelevanteKrebsvorerkrankungen>
<JahrNichtRelevanteKrebsvorerkrankungen></JahrNichtRelevanteKrebsvorerkrankungen>
<DKGPatientenfragebogen></DKGPatientenfragebogen>
<PositiveFamilienanamnese></PositiveFamilienanamnese>
</Anamnese>
<Grundgesamtheiten></Grundgesamtheiten>
<Fallinfos>
<Zentrumsfall></Zentrumsfall>
<Organ></Organ>
<RegNr></RegNr>
<HauptNebenStandort></HauptNebenStandort>
<FallNummer></FallNummer>
<EingabeFalldaten></EingabeFalldaten>
</Fallinfos>
<Diagnose>
<DatumErstdiagnosePrimaertumor></DatumErstdiagnosePrimaertumor>
<DatumHistologischeSicherung></DatumHistologischeSicherung>
<ICDOHistologieDiagnose></ICDOHistologieDiagnose>
<Tumorauspraegung></Tumorauspraegung>
<ICDOLokalisation></ICDOLokalisation>
<KolonRektum></KolonRektum>
<TumorlokalisationRektum></TumorlokalisationRektum>
<praeT></praeT>
<praeN></praeN>
<praeM></praeM>
<UICCStadium></UICCStadium>
<SynchroneBehandlungKolorektalerPrimaertumoren></SynchroneBehandlungKolorektalerPrimaertumoren>
<MRTBecken></MRTBecken>
<CTBecken></CTBecken>
<AbstandFaszie></AbstandFaszie>
</Diagnose>
<PraetherapeutischeTumorkonferenz>
<VorstellungPraetherapeutischeTumorkonferenz></VorstellungPraetherapeutischeTumorkonferenz>
<EmpfehlungPraetherapeutischeTumorkonferenz></EmpfehlungPraetherapeutischeTumorkonferenz>
</PraetherapeutischeTumorkonferenz>
<EndoskopischePrimaertherapie>
<DatumTherapeutischeKoloskopie></DatumTherapeutischeKoloskopie>
<OPSCodeEndoskopischePrimaertherapie></OPSCodeEndoskopischePrimaertherapie>
</EndoskopischePrimaertherapie>
<ChirurgischePrimaertherapie>
<ASAKlassifikation></ASAKlassifikation>
<DatumOperativeTumorentfernung></DatumOperativeTumorentfernung>
<OPSCodesChirurgischePrimaertherapie></OPSCodesChirurgischePrimaertherapie>
<NotfallOderElektiveingriff></NotfallOderElektiveingriff>
<Erstoperateur></Erstoperateur>
<Zweitoperateur></Zweitoperateur>
<AnastomoseDurchgefuehrt></AnastomoseDurchgefuehrt>
<TMEDurchgefuehrt></TMEDurchgefuehrt>
<PostoperativeWundinfektion></PostoperativeWundinfektion>
<DatumPostoperativeWundinfektion></DatumPostoperativeWundinfektion>
<AufgetretenAnastomoseninsuffizienz></AufgetretenAnastomoseninsuffizienz>
<AnastomoseninsuffizienzInterventionspflichtig></AnastomoseninsuffizienzInterventionspflichtig>
<DatumInterventionspflichtigeAnastomoseninsuffizienz></DatumInterventionspflichtigeAnastomoseninsuffizienz>
<Revisionseingriff></Revisionseingriff>
<DatumRevisionseingriff></DatumRevisionseingriff>
<OPmitStoma></OPmitStoma>
<Stomaangezeichnet></Stomaangezeichnet>
</ChirurgischePrimaertherapie>
<PostoperativeHistologieStaging>
<pT></pT>
<pN></pN>
<postM></postM>
<Grading></Grading>
<ICDOHistologiePostoperative></ICDOHistologiePostoperative>
<PSRLokalNachAllenOPs></PSRLokalNachAllenOPs>
<PSRGesamtNachPrimaertherapie></PSRGesamtNachPrimaertherapie>
<GueteDerMesorektumresektion></GueteDerMesorektumresektion>
<AnzahlDerUntersuchtenLymphknoten></AnzahlDerUntersuchtenLymphknoten>
<AbstandAboralerTumorrand></AbstandAboralerTumorrand>
<AbstandZirkumferentiellerTumorrand></AbstandZirkumferentiellerTumorrand>
</PostoperativeHistologieStaging>
<PostoperativeTumorkonferenz>
<VorstellungPostoperativeTumorkonferenz></VorstellungPostoperativeTumorkonferenz>
<EmpfehlungPostoperativeTumorkonferenz></EmpfehlungPostoperativeTumorkonferenz>
</PostoperativeTumorkonferenz>
<Lebermetastasen>
<LebermetastasenVorhanden></LebermetastasenVorhanden>
<LebermetastasenAusschliesslich></LebermetastasenAusschliesslich>
<PrimaereLebermetastasenresektion></PrimaereLebermetastasenresektion>
<BedingungenSenkundaereLebermetastasenresektion></BedingungenSenkundaereLebermetastasenresektion>
<SekundaereLebermetastasenresektion></SekundaereLebermetastasenresektion>
</Lebermetastasen>
<PraeoperativeStrahlentherapie>
<EmpfehlungPraeoperativeStrahlentherapie></EmpfehlungPraeoperativeStrahlentherapie>
<DatumEmpfehlungPraeoperativeStrahlentherapie></DatumEmpfehlungPraeoperativeStrahlentherapie>
<TherapiezeitpunktPraeoperativeStrahlentherapie></TherapiezeitpunktPraeoperativeStrahlentherapie>
<TherapieintentionPraeoperativeStrahlentherapie></TherapieintentionPraeoperativeStrahlentherapie>
<GruendeFuerNichtdurchfuehrungPraeoperativeStrahlentherapie></GruendeFuerNichtdurchfuehrungPraeoperativeStrahlentherapie>
<DatumBeginnPraeoperativeStrahlentherapie></DatumBeginnPraeoperativeStrahlentherapie>
<DatumEndePraeoperativeStrahlentherapie></DatumEndePraeoperativeStrahlentherapie>
<GrundDerBeendigungDerPraeoperativeStrahlentherapie></GrundDerBeendigungDerPraeoperativeStrahlentherapie>
</PraeoperativeStrahlentherapie>
<PostoperativeStrahlentherapie>
<EmpfehlungPostoperativeStrahlentherapie></EmpfehlungPostoperativeStrahlentherapie>
<DatumEmpfehlungPostoperativeStrahlentherapie></DatumEmpfehlungPostoperativeStrahlentherapie>
<TherapiezeitpunktPostoperativeStrahlentherapie></TherapiezeitpunktPostoperativeStrahlentherapie>
<TherapieintentionPostoperativeStrahlentherapie></TherapieintentionPostoperativeStrahlentherapie>
<GruendeFuerNichtdurchfuehrungPostoperativeStrahlentherapie></GruendeFuerNichtdurchfuehrungPostoperativeStrahlentherapie>
<DatumBeginnPostoperativeStrahlentherapie></DatumBeginnPostoperativeStrahlentherapie>
<DatumEndePostoperativeStrahlentherapie></DatumEndePostoperativeStrahlentherapie>
<GrundDerBeendigungDerPostoperativeStrahlentherapie></GrundDerBeendigungDerPostoperativeStrahlentherapie>
</PostoperativeStrahlentherapie>
<PraeoperativeChemotherapie>
<EmpfehlungPraeoperativeChemotherapie></EmpfehlungPraeoperativeChemotherapie>
<DatumEmpfehlungPraeoperativeChemotherapie></DatumEmpfehlungPraeoperativeChemotherapie>
<TherapiezeitpunktPraeoperativeChemotherapie></TherapiezeitpunktPraeoperativeChemotherapie>
<TherapieintentionPraeoperativeChemotherapie></TherapieintentionPraeoperativeChemotherapie>
<GruendeFuerNichtdurchfuehrungPraeoperativeChemotherapie></GruendeFuerNichtdurchfuehrungPraeoperativeChemotherapie>
<DatumBeginnPraeoperativeChemotherapie></DatumBeginnPraeoperativeChemotherapie>
<DatumEndePraeoperativeChemotherapie></DatumEndePraeoperativeChemotherapie>
<GrundDerBeendigungDerPraeoperativeChemotherapie></GrundDerBeendigungDerPraeoperativeChemotherapie>
</PraeoperativeChemotherapie>
<PostoperativeChemotherapie>
<EmpfehlungPostoperativeChemotherapie></EmpfehlungPostoperativeChemotherapie>
<DatumEmpfehlungPostoperativeChemotherapie></DatumEmpfehlungPostoperativeChemotherapie>
<TherapiezeitpunktPostoperativeChemotherapie></TherapiezeitpunktPostoperativeChemotherapie>
<TherapieintentionPostoperativeChemotherapie></TherapieintentionPostoperativeChemotherapie>
<GruendeFuerNichtdurchfuehrungPostoperativeChemotherapie></GruendeFuerNichtdurchfuehrungPostoperativeChemotherapie>
<DatumBeginnPostoperativeChemotherapie></DatumBeginnPostoperativeChemotherapie>
<DatumEndePostoperativeChemotherapie></DatumEndePostoperativeChemotherapie>
<GrundDerBeendigungDerPostoperativeChemotherapie></GrundDerBeendigungDerPostoperativeChemotherapie>
</PostoperativeChemotherapie>
<BestSupportiveCare></BestSupportiveCare>
<Prozess>
<DatumStudie></DatumStudie>
<Studientyp></Studientyp>
<PsychoonkologischeBetreuung></PsychoonkologischeBetreuung>
<BeratungSozialdienst></BeratungSozialdienst>
<GenetischeBeratungEmpfohlen></GenetischeBeratungEmpfohlen>
<GenetischeBeratungErhalten></GenetischeBeratungErhalten>
<ImmunhistochemischeUntersuchungAufMSI></ImmunhistochemischeUntersuchungAufMSI>
</Prozess>
<FollowUp>
<DatumFollowUp></DatumFollowUp>
<LokoregionaeresRezidiv></LokoregionaeresRezidiv>
<LymphknotenRezidiv></LymphknotenRezidiv>
<Fernmetastasen></Fernmetastasen>
<Zweittumor></Zweittumor>
<Verstorben></Verstorben>
<QuelleFollowUp></QuelleFollowUp>
</FollowUp>
</Fall>
</Patient>
First, I have to navigate to certain nodes (for example "DatumXML") and enter a value.
Second, I have to iterate all subnodes of certain nodes (for example Stammdaten) and enter values.
I think the SimpleXMLIterator is going to be your best bet. You didn't quite explain the structure of your XML, but you should be able to do something like:
$iterator = new SimpleXMLIterator($xml);
for ($iterator->rewind(); $iterator->valid(); $iterator->next()) {
$node = $iterator->key();
// Get data from database based on node name
$iterator->{$node} = $data;
}
$finished_xml = $iterator->asXML();
If you're structure is more complex, you should be able to adapt this to what you need. Just remember that a SimpleXMLIterator is a SimpleXMLElement and you can use the same methods and techniques.

Php parsing table does not return the full list of elements

I tried to parse a web page with php, but does not return the integer result of a table, only a part.
the last player returns RAMSEY, Aron ... The other name are loaded after the web page.
Who can help me? I want all the list of players...
$data1=file_get_contents('http://it.soccerwiki.org/squad.php?clubid=1');
$doc=new DOMDocument();
#$doc->loadHTML($data1);
$doc->preserveWhiteSpace=false;
$table=$doc->getElementsByTagName('table');
for($i=0;$i<$table->item(2)->childNodes->length;$i++)
echo $table->item(2)->childNodes->item($i)->textContent;
The wrong result:
Info Naz Giocatore Pos Età Val - MARTÍNEZ, Damián1PO2175- VERMAELEN, Thomas2D(SC)2791- ROSICKÝ, Tomáš256C(C),CO(DSC)3288- BENDTNER, Nicklas16384A(C)2588- WALCOTT, Theo4096CO(D),A(DC)2491- GIBBS, Kieran2D,MD,C(S)2388- WILSHERE, Jack256C,CO(C)2190- OXLADE-CHAMBERLAIN, Alex1024CO(DSC),A(DS)2088- AFOBE, Benik16384A(C)2082- JENKINSON, Carl8D(D)2185- YENNARIS, Nicholas8D(D),MD(C)2075- JEFFREY, Anthony1024CO,A(S)1875- ARTETA, Mikel32MD,C(C)3191- CAZORLA, Santi256C(C),CO(DSC)2892- MONREAL, Nacho2D(S)2789- FLAMINI, Mathieu32MD,C(C)2988- SAGNA, Bacary8D(D)3091- KOSCIELNY, Laurent4D(C)2790- DIABY, Abou32MD,C,CO(C)2789- GIROUD, Olivier16384A(C)2690- SANOGO, Yaya16384A(C)2082- PODOLSKI, Lukas1024CO,A(SC)2891- MERTESACKER, Per4D(C)2891- ÖZIL, Mesut1024CO(DSC)2494- GNABRY, Serge1024CO(DSC)1877- EISFELD, Thomas256C,CO(C)2075- FRIMPONG, Emmanuel32MD,C(C)2183Prs VIVIANO, Emiliano1PO2789- MIYAICHI, Ryo1024CO,A(DS)2084- PARK, Chu-Young1024CO,A(DSC)2887- FABIAŃSKI, Lukasz1PO2886- SZCZĘSNY, Wojciech1PO2389- RAMSEY, Aaron256C,CO(DC)2288
Actually your data is right. But there is jquery sorting on page loaded. Just different player row places.
I copied HTML codes and removed js files, last player was RAMSEY, Aaron

Put XML string (node value) in server text file and retrieve and echo it again (PHP)

This is my problem. I'm trying to retrieve a value from an XML url (from last.fm api). For example the biography of an artist.
I already know that I can do it simply like this (e.g. for Adele):
<?php
$xml = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=adele&api_key=b25b959554ed76058ac220b7b2e0a026");
$info = $xml->artist->bio->summary;
echo $info;
?>
This returns:
Adele Laurie Blue Adkins, (born 5 May 1988), is a Grammy Award-Winning English singer-songwriter from Enfield, North London. Her debut album, <a title="Adele - 19" href="http://www.last.fm/music/Adele/19" class="bbcode_album">19</a>, was released in January 2008 and entered the UK album chart at #1. The album has since received four-times Platinum certification in the UK and has sold 5,500,000 copies worldwide. The album included the hugely popular song <a title="Adele – Chasing Pavements" href="http://www.last.fm/music/Adele/_/Chasing+Pavements" class="bbcode_track">Chasing Pavements</a>. 19 earned Adele two Grammy Awards in February 2009 for Best New Artist and Best Female Pop Vocal Performance.
I would now like to put that result in a text file and store it on a folder on my website, for example: "http://mysite.com/artistdescriptions/adele.txt".
I've already tried:
<?php
$file_path = $_SERVER['DOCUMENT_ROOT'].'/artistdescriptions/adele.txt';
$xml = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=adele&api_key=b25b959554ed76058ac220b7b2e0a026");
$info = $xml->artist->bio->summary;
file_put_contents($file_path, serialize($info));
$file_contents = file_get_contents($file_path);
if(!empty($file_contents)) {
$data = unserialize($file_contents);
echo $data;
}
?>
But this unfortunately didn't work. Any help would be greatly appreciated!
Echo call magic method __toString(), but serialize doesn't, and in SimpleXMLElement isn't serialize allowed, so it throw an Exception. But you can call __toString() magic method by yourself, and this solve you problem.
Replace your line with mine
$info = $xml->artist->bio->summary->__toString();

Categories