xandrani Posted April 21, 2010 Share Posted April 21, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/199328-getting-schemalocation-value-from-xml-file-using-domdocument-or-simplexml/ Share on other sites More sharing options...
salathe Posted April 21, 2010 Share Posted April 21, 2010 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; Quote Link to comment https://forums.phpfreaks.com/topic/199328-getting-schemalocation-value-from-xml-file-using-domdocument-or-simplexml/#findComment-1046154 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.