Altova XMLSpy 2025 Professional Edition

Objects and Dependencies

Home Prev Top Next

Within the definition of an object, you might want to specify that if a certain property is present then a second dependent property must also be present. The mandatory presence of the second property is dependent on, and follows from, the presence of the first property. Here is a scenario containing a dependency. An object (named, say, member) has a property called credit_card, which is defined as optional. If the credit_card property is present, then a second property named billing_address must be present. The billing_address property is dependent on, and follows from, the credit_card property:

 

This kind of dependency can be specified in one of two ways:

 

as a property dependency (the dependent structure is a property)

as a schema dependency (the dependent structure is a schema)

 

Property dependencies

The screenshot below shows an object having a name property (required), a credit_card property (optional ), and a billing_address property (dependent). The billing_address property is dependent on the credit_card property. The code of this JSON object definition is listed below the screenshot. How to create a property dependency is described further below.

JSONPropDependencies01

 

To create a property dependency, do the following:

 

1.Right-click the property on which the dependency will be based. (In our example this is the credit_card property.)

2.In the context menu that appears, select Add Dependency | Dependent Property. A new property is added with an Occurrence value of Dependent.

3.Define the name and value of this property, and add any additional details or constraints you want.

 

To specify a property as being dependent on another property, do the following:

 

1.Right-click the property you want to make dependent on another property. (In our example this is the billing_address property.)

2.In the context menu that appears, select Dependent. Alternatively, in the Details entry helper, go to the Occurrence entry, and select Dependent (see screenshot above).

3.In the Details entry helper, click the dropdown list icon of the Dependent On entry. The dropdown list displays all the other properties of the object. Select the property on which you want the current property to depend.  

 

Note:An icon appears in the boxes of both properties involved in a dependency (see screenshot above). Double-clicking the icon of one property takes you to the other property.

 

Note:A property can have multiple dependent properties.

 

Schema dependencies

The screenshot below shows an object that describes the same instance data structure as the object discussed in the previous section. The definitions of the two objects, however, are different. While the previous definition used a property dependency to define the billing_address property as being dependent on the credit_card property, the current definition uses a schema dependency to define this dependency. The code of this latter JSON object definition is listed below the screenshot. How to create a schema dependency is described further below

Click to expand/collapse

 

To create a schema dependency, do the following:

 

1.Right-click the property on which the dependency will be based. (In our example this is the credit_card property.)

2.In the context menu that appears, select Add Dependency | Schema Dependency. A new object definition is created. It will have the same name as the property on which it is dependent (in our example, credit_card), and it will have a child sub-schema.

3.Define the sub-schema the way you want it, adding any additional details or constraints you may want.

 

Note:An icon appears in the boxes of the property and object involved in a dependency (see screenshot above). Double-clicking the icon in one box takes you to the other box.

 

Note:If you wish to set multiple dependencies, do this within the dependent sub-schema (see screenshot above).

 

© 2018-2024 Altova GmbH