0

Out of dozens of xml and xsd files I'm trying to match the corresponding files together via their namespaces in order to parse accordingly. My predecessor just tried to hard-code it in which leads to a lot of exceptions. Although I see here that it isn't a primary goal for a namespace to be retrievable, would there be a way to do so?

    <?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://cwe.mitre.org/cwe-6" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cwe="http://cwe.mitre.org/cwe-6" xmlns:xhtml="http://www.w3.org/1999/xhtml" elementFormDefault="qualified" attributeFormDefault="unqualified" version="6.0">
    <xs:import namespace="http://www.w3.org/1999/xhtml" schemaLocation="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd"/>
    <xs:annotation>
        <xs:documentation>The CWE Schema is maintained by The MITRE Corporation and developed in partnership with the public CWE Community. For more information, including how to get involved in the project and how to submit change requests, please visit the CWE website at https://cwe.mitre.org.</xs:documentation>
        <xs:appinfo>
            <schema>Core Definition</schema>
            <version>6.0.0</version>
            <date>08 November 2017</date>
  • 1
    The targetNamespace attribute of the `xs:schema` element is an XML attribute like any other; what exactly is your difficulty in reading it like any other attribute? – Michael Kay Jul 12 '19 at 14:12
  • 1
    Your question title asks about how to retrieve a namespace from an XSD file. As @MichaelKay comments, `xs:schema/@targetNamespace` is readily available as an XML attribute. The body of your question, however, appears to suggest that your actual problem relates to determining the XSD intended to be used to validate a given namespaced XML document. That's a harder problem, but see [Where to look for an XSD given an XML namespace](https://stackoverflow.com/q/25858335/290085). – kjhughes Jul 12 '19 at 15:14
  • When searching for a single node by "schema" Rather then pull the attribute associated with xs:schema node, it skips over it altogether and pulls Core Definition instead. – KeyboardSmash Jul 15 '19 at 16:55

0 Answers0