question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to represent XML elements with attributes

See original GitHub issue

Suppose 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:open
  • Created 7 years ago
  • Reactions:12
  • Comments:33 (11 by maintainers)

github_iconTop GitHub Comments

19reactions
MikeRalphsoncommented, Dec 11, 2017

As we have the attribute property on the xml object already, perhaps it makes sense to add a text 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 marked text: true?

Thus

location:
  type: "object"
  properties: 
    coordinate: 
      type: "object"
      properties: 
        format: 
          type: "string"
          xml: 
            attribute: true 
        value: 
          type: "string"
          xml:
            text: true

would represent the xml

<location>
  <coordinate format="lat-lon">a-b</coordinate>
</location>
9reactions
dinamiccommented, Dec 5, 2018

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 or inline: true.

How should we move this forward?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found