简体   繁体   中英

XML data types specification

While there is plenty of documentation about XML document structure, there are very few links to how non textual data (eg. integer and decimal numbers, boolean values) should be managed.
Is there a consolidated standard? Could tell me a good starting point?
POST SCRIPT
I add an example because the question is actually too generic.

I've defined a document structure:

<rectangle>
  <width>12.45</width>
  <height>23.34</heigth>
  <rounded_corners>true</rounded_corners>
</rectangle>

Since I'm using DOM, the API is oriented to textual data. Say doc is an instance of Document . doc.createTextNode("takes a string") . That is: API doesn't force towards a particular rapresentation.
So two question arise:
1) saving bolean true as 'true' instead of uhm, 1/0 is a standard?
2) i have to define simple methods that write and parse from and to this string representations. Example. I may use java wrappers to do this conversion:

Float f = 23.34;
doc.createTextNode(f.toString());

but does it adhere to the xml standard for decimal numbers? If so, i can say that a non-java programs can read this data because the data representation is xml.
why not jaxb
This is just an example, my xml is made up of a big tree of data and i need to write and read just a little part of it, so JAXB seems not to fit very well. Binding architecture tends to establish a tight copuling between xml structure and class structure. Good implementations like moxy let you loosen this coupling, but there are cases in wich the two structures simply don't match. In those cases, the DTO used to adapt them would be more work than using DOM.

Of course, there are dozens of official standards related to core XML. Some of the important ones:

  1. XML schema 1.1 overview
  2. XML schema 1.1 - datatypes ('XSD')
  3. XML schema 1.1 - structures
  4. Core XML overview
  5. XML 1.0
  6. XML 1.1

Further specification like XPath, XQuery are available at www.w3.org/standards/xml/ . As you tagged this question with java you may be interested in JAXB as well, which defines a standard approach for mapping XML to Java and vice versa.

You can leverage the javax.xml.bind.DatatypeConverter class to convert simple Java types to a String that conforms to the XML Schema specification:

Float f = 23.34f;
doc.createTextNode(DatatypeConverter.printFloat(f));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM