3 ms·
>> XML offers both tag attributes and child tags and when encoding data it's not obvious which one to use. >> The usage is obvious when using XML as markup, bu
by thesuperbigfrog 6y ago
>> XML offers both tag attributes and child tags and when encoding data it's not obvious which one to use.
>> The usage is obvious when using XML as markup, but when used for data it's left to the one creating the particular spec.
Either approach is valid. Having a choice about how to structure the data is not a bad thing.
My preferred approach is to use attributes for simple key-value pairs that are mainly used to select structured data found in child tags. If you have configuration data that is stored as XML, you could use attibutes to mark where the contained structured data should be used. For example: 1) language localization data could be stored stored in XML with attributes describing the language or locale; 2) build configuration settings might be stored in XML with attributes describing the target platform or CPU architecture.
For more formalized data formats, create an XML Schema that defines what the XML data should look like and then you can easily validate that the XML data is structured correctly and even generate parsers or XML to programming language bindings.
- SiempreViernes 6y ago> Either approach is valid. Having a choice about how to structure the data is not a bad thing. I though the point of using a well defined markup language was exactly that it imposed a clear structure on your data. In another sense, xml gives no options: your data is going to live in a string.
- thesuperbigfrog 6y ago>> I though the point of using a well defined markup language was exactly that it imposed a clear structure on your data. A clear structure can be defined with an XML Schema Definition (XSD) document: https://en.wikipedia.org/wiki/XML_Schema_(W3C) https://en.wikipedia.org/wiki/XML_Schema_(W3C) An XML Schema Definition defines the structure and allowable content for a given XML document and allows XML data to be programmatically validated to ensure it adheres to the specified format and content. >> In another sense, xml gives no options: your data is going to live in a string. This is true. XML is inherently text-based. There are options for binary data formats depending on your needs.