php - How parsing out XML file with namespaces? -
i know similar questions posted before, can't parse out xml file namespaces.
here link because it's big post here: https://tsdrapi.uspto.gov/ts/cd/casestatus/sn86553893/info.xml
i tried using simplexml_load_file
not create xml object. found similar problems , try this, provided downloaded file named 86553893.xml
here php code:
$xml= new simplexmlelement("86553893.xml"); foreach($xml->xpath('//com:applicationnumber') $event) { var_export($event->xpath('com:applicationnumbertext')); }
you have register namespaces on each element want use them:
$xml= new simplexmlelement("86553893.xml"); $xml->registerxpathnamespace('com', 'http://www.wipo.int/standards/xmlschema/common/1'); foreach ($xml->xpath('//com:applicationnumber') $event) { $event->registerxpathnamespace( 'com', 'http://www.wipo.int/standards/xmlschema/common/1' ); var_export($event->xpath('com:applicationnumbertext')); }
this different in dom, use domxpath instance, single object , have register namespaces once.
$dom = new domdocument(); $dom->load("86553893.xml"); $xpath = new domxpath($dom); $xpath->registernamespace('com', 'http://www.wipo.int/standards/xmlschema/common/1'); foreach ($xpath->evaluate('//com:applicationnumber') $event) { var_export($xpath->evaluate('string(com:applicationnumbertext)', $event)); }