views:

17

answers:

1

Hi!
...well, actually I have an object which looks like this:

object(AleParserXMLElement)#39 (4) {
  ["name:private"]=>
  string(6) "rowset"
  ["data:private"]=>
  object(SimpleXMLElement)#42 (2) {
    ["@attributes"]=>
    array(3) {
      ["name"]=>
      string(6) "skills"
      ["key"]=>
      string(6) "typeID"
      ["columns"]=>
      string(36) "typeID,skillpoints,level,unpublished"
    }
    ["row"]=>
    array(185) {
      [0]=>
      object(SimpleXMLElement)#70 (1) {
        ["@attributes"]=>
        array(3) {
          ["typeID"]=>
          string(4) "3377"
          ["skillpoints"]=>
          string(6) "256000"
          ["level"]=>
          string(1) "5"
        }
      }
      [1]=>
      object(SimpleXMLElement)#23 (1) {
        ["@attributes"]=>
        array(3) {
          ["typeID"]=>
          string(5) "20342"
          ["skillpoints"]=>
          string(1) "0"
          ["level"]=>
          string(1) "0"
        }
      }
      [2]=>
      object(SimpleXMLElement)#9 (1) {
        ["@attributes"]=>
        array(3) {
          ["typeID"]=>
          string(5) "12096"
          ["skillpoints"]=>
          string(1) "0"
          ["level"]=>
          string(1) "0"
        }
      }
      //etc.
    }
  }
  ["children:private"]=>
  NULL
  ["rows:private"]=>
  NULL
}

And I have an XML file which you can see here:

link

I would like to display those skills from my first object, but replace their typeID values with typeName from that xml file.
As you assume, I have no idea at all how to do that :) Please help!

+1  A: 

You can use DOMDocuent and DOMXpath to fetch the name. An XPath expression like //row[@typeID="ID HERE"]/@typeName will do:

$d = new DOMDocument;
$d->load(...);
$xp = new DOMXpath($d);
$name = $xp->query('//row[@typeID="ID HERE"]/@typeName');
echo $name->item(0)->value;

As to how you do your replacement, refer to the docs of the XML parser you're using (I see a AleParser that wraps a SimpleXMLElement there, but have no idea what that is).

Artefacto
Thanks for helping! I really don't know sh** about this XML stuff and for some reason it is extremely confusing to me :) Whatever I try I get "Warning: DOMXPath::query() [domxpath.query]: Invalid expression in..." error! My query looks like this $name = $xp->query('string(//row[@typeID='.$skill->typeID.']/@typeName'); and $skill->typeID comes from foreach loop which iterates through my object... AleParser is an API library for Eve-Online game - http://code-box.sk/software/ale.html
errata
@errata Fixed now.
Artefacto
Ah yes :))) It works perfectly :) Many many thanks!
errata