1

I'm reviewing the XML for the UPS Shipping API, and the XSD contains this block:

  <xsd:complexType name="PackageType">
    <xsd:sequence>
      <xsd:element name="Description" type="xsd:string" minOccurs="0"/>
      <xsd:element name="PackagingType" type="PackagingTypeType" minOccurs="0"/>
      <xsd:element name="Dimensions" type="DimensionsType" minOccurs="0"/>
      <xsd:element name="DimWeight" type="PackageWeightType" minOccurs="0"/>
      <xsd:element name="PackageWeight" type="PackageWeightType" minOccurs="0"/>
      <xsd:element name="LargePackageIndicator" type="xsd:string" minOccurs="0"/>

...

I'd like to see what the possible values for PackageWeightType are, but I can't figure out how to backtrack. The top of the XSD is

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:ups="http://www.ups.com/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" version="201707">
  <xsd:include schemaLocation="IF.xsd"/>

but there's nothing in IF.xsd that I can see that would help me in my quest.

What are my next steps?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
Scott C Wilson
  • 19,102
  • 10
  • 61
  • 83

1 Answers1

2

The same XSD that houses PackageType (ShipConfirmRequest.xsd, version 201707) also contains PackageWeightType:

<xsd:complexType name="PackageWeightType">
    <xsd:sequence>
        <xsd:element name="UnitOfMeasurement" type="UnitOfMeasurementType"/>
        <xsd:element name="Weight" type="xsd:string"/>
    </xsd:sequence>
</xsd:complexType>

and UnitOfMeasurementType as well:

<xsd:complexType name="UnitOfMeasurementType">
    <xsd:sequence>
        <xsd:element name="Code" type="xsd:string"/>
        <xsd:element name="Description" type="xsd:string" minOccurs="0"/>
    </xsd:sequence>
</xsd:complexType>

Generally, to find a declaration:

  1. Search first in the XSD in which you see its use.
  2. Search next in the included/imported XSD files, and their included/imported XSDs, recursively. (Typically, if all files are in a common directory, grepping the directory tree recursively will suffice.)

If the component is in the same namespace, you need only look in the original XSD and the transitive closure of the included XSDs. If the component is in a different namespace, you can typically find the XSD based upon the referenced namespace.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • How can I deduce the possible values from this though if `Code` is just a string? (How can I know if "OZS" is a possible code, for example?) – Scott C Wilson Dec 23 '17 at 05:40
  • If Code is declared as xs:string, then the schema imposes no constraints on its value. There may be constraints imposed by some other mechanism (e.g. validation applied to user input fields on a form), but if the schema doesn't define the constraints then there's no point looking for them in the schema. – Michael Kay Dec 23 '17 at 09:30