Jump to content

Question about dom xpath queries


matrygg

Recommended Posts

Hi,

 

This is my first post, so hopefully I'm breaking any customs here.

 

I'm having a bit of trouble navigating my way around the Dom commands in PHP 5.  I want to parse a XML page from the library of congress -- an example of which is here:

 

http://z3950.loc.gov:7090/voyager?version=1.1&operation=searchRetrieve&query=bath.isbn=0812238001&maximumRecords=1&recordSchema=mods

 

I can load it into a dom object just fine, and I can use the getElementsByTagName command without any difficulty.  However, I would rather use xpath, but when I try to do so I just get a null result.  This is what I've got so far:

 

$open_URL = WebOpen($URL); //function to open the URL and grab the xml

$dom= domxml($open_URL); //function that loads the xml as a dom object

$xp = new domxpath($dom);
$names = $xp->query("/name/namePart");
foreach ($names as $node) {
    print $node->textContent . " ";
}

 

I've also tried setting the query up from the root forward, but it dies on the mods node for some reason.  Basically, any time I try to use xpath I seem to get a null result, so I'm sure I'm doing something wrong, but I can't figure out what.

Link to comment
https://forums.phpfreaks.com/topic/164729-question-about-dom-xpath-queries/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.