Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML - Quoting Numerical Attributes

Should numerical attributes in XML be quoted?

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

vs.

<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're required.

like image 766
cltatman Avatar asked Jun 18 '12 14:06

cltatman


People also ask

Should XML attributes be quoted?

Attribute values must always be quoted It is illegal to omit quotation marks around attribute values. XML elements can have attributes in name/value pairs; however, the attribute value must always be quoted.

How do you quote in XML?

From the XML specification: To allow attribute values to contain both single and double quotes, the apostrophe or single-quote character (') may be represented as "&apos;", and the double-quote character (") as "&quot;".

What is attr in XML?

The Attr object represents an attribute of an Element object. The allowable values for attributes are usually defined in a DTD. Because the Attr object is also a Node, it inherits the Node object's properties and methods.

How do I pass multiple values in XML?

use a “primitive attribute” and append, with a separator character, the multiple values into one string, or. use the FME attribute list, or. retain one attribute value out of the multiple values.


1 Answers

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

XML Attributes Must be Quoted

Attribute values must always be quoted. Either single or double quotes can be used. For a person's sex, the person element can be written like this:

<person sex="female">

or like this:

<person sex='female'>

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

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

or you can use character entities:

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

Updated to expand based on the newest comment, according the Microsoft universe at least.

XElement.Value Property

public string Value { get; set; }

You can also see refer to this question as well

like image 89
conroyrw Avatar answered Oct 20 '22 01:10

conroyrw