Jump to content

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


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;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.