How to represent XML elements with attributes
See original GitHub issueSuppose I have the following XML:
<location>
<coordinate format="lat-lon">a-b</coordinate>
</location>
I this the correct way to represent this using Swagger Schema objects?
---
type: "object"
xml:
name: "location"
properties:
coordinate:
type: "string"
properties:
format:
type: "string"
xml:
attribute: true
It seems weird for the “coordinate” property … which itself is of type “string” to contain a “properties” field. Coming from JSON-Schema-Draft-V4 background, you would not expect a “string” field to have properties, because there is no such thing in JSON.
But then again, this is a “Swagger Schema Object” … not a JSON-Schema-Draft-V4. I just want confirmation whether or not this is the correct way to do it.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:12
- Comments:33 (11 by maintainers)
Top Results From Across the Web
XML Elements vs. Attributes - W3Schools
If you use attributes as containers for data, you end up with documents that are difficult to read and maintain. Try to use...
Read more >XML - Attributes - Tutorialspoint
This chapter describes the XML attributes. Attributes are part of XML elements. An element can have multiple unique attributes. Attribute gives more ...
Read more >XML | Attributes - GeeksforGeeks
The XML attribute is a part of an XML element. The addition of attribute in XML element gives more precise properties of the...
Read more >Controlling XML Serialization Using Attributes - Microsoft Learn
Using these attributes, you can control the element name, namespace, and XML Schema (XSD) data type as defined in the W3C document titled ......
Read more >XML Schema Tutorial - Defining Elements and Attributes
It can also describe the type and values that can be placed into each element or attribute. The XML data constraints are called...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As we have the
attribute
property on thexml
object already, perhaps it makes sense to add atext
property (also of type boolean) to indicate that the property represents the xml text node, where at most only one property of an object SHOULD be markedtext: true
?Thus
would represent the xml
I stumbled upon this issue today. I guess the problem is not with the attributes - they work fine, the problem is with objects that have both attributes and a value. Maybe the title of the issue could be rephrased to indicate that?
Solution wise… I’m +1 on
text: true
orinline: true
.How should we move this forward?