Jump to content

Getting schemaLocation value from XML file (using DomDocument or SimpleXML?)


xandrani

Recommended Posts

Is it possible to extract the schemaLocation from an XML file using an appropriate call?

 

I know I can easily use a regex but if there was an official way to get the schemaLocation then I'd prefer it.

 

 

Example snippet of XML file:

 

<?xml version="1.0" encoding='UTF-8'?>
<books
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="file:///documents%20and%20settings/Fred/Desktop/example.xsd">
<book> ...

 

A function such as:

get_schema_location(&$schema_location)

 

would return by reference the string:

"file:///documents%20and%20settings/Fred/Desktop/example.xsd"

 

Any ideas? :)

DOM (where $doc is a DOMDocument)

 

$doc->documentElement->getAttributeNS($dom->lookupNamespaceURI('xsi'), 'schemaLocation');

 

SimpleXML (where $doc is a SimpleXMLElement)

 

echo $doc->attributes('xsi', TRUE)->schemaLocation;

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.