PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

 
Last updated: Fri, 29 Aug 2008

view this page in

DOMXPath::registerNamespace

(No version information available, might be only in CVS)

DOMXPath::registerNamespace DOMXPath オブジェクトの名前空間を登録する

説明

bool DOMXPath::registerNamespace ( string $prefix , string $namespaceURI )

DOMXPath オブジェクトに、 namespaceURI および prefix を登録します。

パラメータ

prefix

プレフィックス。

namespaceURI

名前空間の URI。

返り値

成功した場合に TRUE を、失敗した場合に FALSE を返します。



 
Last updated: Fri, 29 Aug 2008
 
add a note add a note User Contributed Notes
DOMXPath::registerNamespace
adam dot prall at thinkingman dot com
08-Jun-2008 02:49
Just a quick "gotcha" that may sound stupid:

If you've registered your namespaces, loaded your XHTML, etc., into your XPath's DOMDocument object and <i>still</i> can't get it to work, check to make sure you haven't used the DOMDocument's loadHTML() or loadHTMLFile() function. For XHTML <i>always use the XML versions</i>, otherwise your XPath will never, ever work. Save yourself a couple hours of frustration...
cameron kellough
14-Apr-2007 10:33
This is called prefix mapping and it is necessary to use xpath to handle documents which have default namespaces. //root/item will search for items with no namespace, not items with the namespace described as the default in the xmlns declaration.  This problem is maddening as it just looks on the surface like xpath isn't working.
spam at spam dot spam
31-Mar-2005 12:46
It is mentioned in a few places on the web, but it wasn't mentioned here. You need to use this function to set up a prefix for the default namespace of a document.

For instance, if you are trying to parse a Microsoft Spreadsheet XML file, which has the default namespace of "urn:schemas-microsoft-com:office:spreadsheet":

$doc = DOMDocument::load("my_spreadsheet.xml);
$xpath = new DOMXPath($doc);
$xpath->registerNamespace("m",
        "urn:schemas-microsoft-com:office:spreadsheet");
$query = '/m:Workbook/m:Worksheet[1]/m:Table';
$result = $xpath->query($query, $doc);

You can use anything in place of the 'm', but you have to specify something! Just asking for "/Workbook/Worksheet/Table" doesn't work.

 
Last updated: Fri, 29 Aug 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites