0

I'm new to XML and I'm having a hard time grabbing the MarketRent. I'm trying to target all the ILS_Unit with a certain id and grab the MarketRent nodeValue. But there is a namespace, which I register, but I'm receiving a blank page.

My PHP Code:

<?php
$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;
$doc->load('http://mdoerrdev.com/xml/updates-mits.xml');

$xpath = new DOMXPath($doc);
$xpath->registerNamespace('MITS', "http://mdoerrdev.com/xml/updates-mits.xml");

$unitPrice = $xpath->evaluate("//ILS_Unit[@FloorplanId='550584']/Unit/MITS:Information/MITS:MarketRent");
    foreach($unitPrice as $up)  {
        var_dump($up);
    };
?>

The Input XML:

Input XML is too big, so you can find it here: http://mdoerrdev.com/xml/updates-mits.xml

1
  • Could you be so kind the next time you ask a question posting the relevat information on this website into your question Commented Sep 25, 2013 at 14:18

1 Answer 1

1

If you register the namespace, make sure the URI matches the one in the XML, change:

 $xpath->registerNamespace('MITS', "http://mdoerrdev.com/xml/updates-mits.xml");

to

 $xpath->registerNamespace('MITS', "http://www.mitsproject.org/namespace");
Sign up to request clarification or add additional context in comments.

4 Comments

I made this change. Still getting a blank document. Something else must be wrong.
Oh I had a type, this is what I get now, mdoerrdev.com/xml/testing2.php . How do I now go from that to target just the MarketRent ?
You are executing XPath //ILS_Unit[@FloorplanId='550584']/Unit/Information/MarketRent. This will find all MarketRent elements with the FloorplanId given in de XPath. The XML found on pastie.org does not contain this FloorplanId. But I think it is found more than once
Maybe you are searching for this XPath: //Property/Floorplan[@Id='550578']/MarketRent

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.