XML - Quoting Digital Attributes

Should numeric attributes be quoted in XML?

<root>
  <node size=45 />
  <foo bar=1.2>
    <baz foo=20>
  </foo>
</root>

against.

<root>
  <node size="45" />
  <foo bar="1.2">
    <baz foo="20">
  </foo>
</root>

My code editor / browser seems fine without quotes, but most online resources seem to say they are required.

+5
source share
1 answer

http://www.w3schools.com/xml/xml_attributes.asp

XML attributes must be specified

Attribute values ​​must always be specified. You can use single or double quotes. For a person’s gender, a person’s element can be written as follows:

<person sex="female">

or like this:

<person sex='female'>

If the value of the attribute itself contains double quotes, you can use single quotes, as in this example:

<gangster name='George "Shotgun" Ziegler'>

or you can use character objects:

<gangster name="George &quot;Shotgun&quot; Ziegler">
+3
source

All Articles