Search code examples
web-servicesxpathxsdwsdl

WSDL references to other files


I'm writing a program which fetches a WSDL and any imported files, then saves them to a single directory. What I want to do as part of this is to flatten the file structure so there's just one directory which contains all the files referenced by the WSDL or referenced by its referenced files. So I need to go into each file and wherever there's an import, I need to strip the path out of the name. Here's an example:

<xsd:import schemaLocation="xsds/Currency.xsd" namespace="urn:example.com:enterprise:schemas:reference:currency">
</xsd:import>

So the import above references the file xsds/Currency.xsd and I want to just extract Currency.xsd from this. I can get the content of this attribute with an XPath expression to match the tag like so:

//*[local-name()='import']/@schemaLocation

However, there are probably other types of tags where a WSDL or it's referenced xsds might import files which this XPath expression won't match. What are the other tags or field names I might need to match on so I don't miss any files?


Solution

  • You might want to use

    //@schemaLocation
    

    which would catch all schemaLocation attributes independent of where they occur.

    Elements that contain the schemaLocation attributes in the XSD namespace:

    1. import
    2. include
    3. redefine

    You should be aware that in the XMLSchema-instance namespace, the qualified schemaLocation attribute will contain space separated pairs where each even-numbered component is a location (the odd-numbered items are namespaces).