2

I understand how to write XML for Android. I would like to somehow define, for lack of the correct term, class for XML, so that I can create instances of it and require certain attributes or elements. A few hours of Googling didn't help, so I am here as a last resort. Here's a little more detail of what I'd like to do.

<CLASS-TEMPLATE>
 <required_element required_attribute=""></required_element>
 <required_element required_attribute=""></required_element>
</CLASS-TEMPLATE>

<Class-Instance id="0" name="name">
     <required_element required_attribute="0">Something</required_element>
     <required_element required_attribute="1">Something else</required_element>
</Class-instance>

I would like the Intellij compiler to inform me that I am missing attributes or elements like it does for Android, but I have no idea how to. I experimented with xsl:templates but I am lost.

TL;DR How can I make regular XML act like Android xml, so I can define required attributes and elements for a class I define and instantiate?

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
Andrew No
  • 535
  • 6
  • 20
  • 4
    The word you are looking for is "schema". A schema describes a class of XML documents. You will find lots of information (on StackOverflow and elsewhere) by searching for "schema for Android XML". – Michael Kay Sep 12 '15 at 08:36
  • Here's an [introduction to XML Schema](https://www.simple-talk.com/sql/learn-sql-server/introduction-to-xml-schema/). However, there is no default [schema for Android XML](https://groups.google.com/forum/#!topic/android-developers/2FtsLQ4wESY), so you will have to roll your own. I'm afraid you will have to sieve through the TL;DR this time... – Abel Sep 12 '15 at 10:31
  • @MichaelKay yes, that is exactly what I need. Thank you! – Andrew No Sep 12 '15 at 16:12
  • @Abel thanks for the link! – Andrew No Sep 12 '15 at 16:13

0 Answers0