Develop
Develop
Select your platform

Auto-validate XML files using XSD

Updated: Jul 8, 2025
Editing XML files can be a challenging task, especially if you’re working with complex data structures. XML Schema Definition (XSD) is a powerful tool that provides a set of rules and constraints for XML documents. By using an XSD file, you can validate your XML files against a predefined schema, ensuring accuracy and consistency. Spatial SDK offers its own XSD file that you can configure in Android Studio to help you correctly format your component XML files.

Configure Android Studio to use the XSD

  1. Open Android Studio.
  2. Select File > Settings.
    The Settings window opens.
  3. Select Languages & Frameworks > Schemas and DTDs.
  4. In the main section of the panel, click the + that’s underneath the text “External schemas and DTDs”.
  5. Paste the XSD URL into the URL text field and then click Okay.
    You can find the URL for specifics version of the XSD in the corresponding release notes.
  6. Click Apply and then click Okay.
  7. In the root element of each XML file that should use the schema, add these attributes.
     <ComponentSchema packageName="com.meta.spatial.samples.customcomponentssample"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="https://developers.meta.com/horizon/spatial-sdk/latest/ComponentSchema.xsd/">
    
    Here’s an example of a component XML file with the attributes added:
     <ComponentSchema packageName="com.meta.spatial.samples.example"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="https://developers.meta.com/horizon/spatial-sdk/latest/ComponentSchema.xsd/">
    <Enum name="Example Enum">
        <EnumValue value="Enum Option 1" />
        <EnumValue value="Enum Option 2" />
    </Enum>
    <Component name="Example Component">
        <BooleanAttribute name="Example Boolean Attribute"></BooleanAttribute>
        <FloatAttribute name="Example Float Attribute" defaultValue="0f"></FloatAttribute>
    </Component>
     </ComponentSchema>
    
    Now that the XSD file is set up, Android Studio will provide autocomplete suggestions.
    Autocomplete suggestions in Android Studio
Did you find this page helpful?
Thumbs up icon
Thumbs down icon