1

Im using PHP to load a XML document:

$xmlDocument = file_get_contents($url, false, $context);
$xmlString = simplexml_load_string($xmlDocument);

XmlString and $url : http://testing.zwiink.us/getPurchased.php

Now im trying to filter out each element, which contains:

[u] => /zwinky/fds/creations/

I tried to use xpath, but always failed, i guess i used a wrong search value. Does anyone hava a idea how I would get this working?

dane
  • 25
  • 2
  • do you also have the path where the xml is located live online? that url you got in the question doesn't really much help since that code dump is not properly formatted – Kevin Nov 09 '14 at 09:31
  • http://testing.zwiink.us/getPurchased.php or original http://outfits.zwinky.com/users/908/721/swagg_ma_blue/purchased.xml?v=616319 – dane Nov 09 '14 at 09:32

1 Answers1

0

You need to make an xpath query first with using contains():

$xmlDocument = file_get_contents($url, false, $context);
$xmlString = simplexml_load_string($xmlDocument);

// target elements with that attribute
$u = $xmlString->xpath('//*[contains(@u, "/zwinky/fds/creations/")]');

echo '<pre>';
print_r($u);
Kevin
  • 41,694
  • 12
  • 53
  • 70
  • The only problem with that is, its returning also a empty array, as everythign else i tried :( See: http://testing.zwiink.us/test.php – dane Nov 09 '14 at 09:37
  • @dane is this url `http://outfits.zwinky.com/users/908/721/swagg_ma_blue/purchased.xml?v=616319` really accessible? i can't access it, its loading endlessly. can you make an alternative copy of that xml. maybe post the xml in pastebin.com? – Kevin Nov 09 '14 at 09:39
  • @dane wow, thats a lot of xml, anyways here is a demo, its working fine with the one you provided http://codepad.viper-7.com/7bNdiN. it got 30+ elements found. now i know why its slow, its a large xml – Kevin Nov 09 '14 at 09:44