XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] XML is text-only ... why?

You have mentioned three aspects of a XML document, as shown below:

1) The XML document itself
<?xml version="1.0"?>
<x>23</x>

2) Processing of the XML document
<xsl:value-of select="x * 2"/>

3) Writing a Schema for this XML document
<element name="x" type="integer"/>

The superficial syntax (which is visible to our eyes in a text editor,
or the lexical representation) just *conveys* the semantics of the
syntax.

But the intended behavior (or functioning) of this syntax is taken
care by the appropriate processor (the XML parser, XSLT processor or a
Schema processor).

I think this is true even for a different system, for e.g. a Java
program and its compiler.

If this is a Java class:

class test {
  int i = 0;

  //some more instructions
}

We are writing this program in a text editor (just like the XML
example you gave), and 0 in a text editor is a string (or text). But
the Java compiler would translate this program into the byte code,
where int i = 0; will be treated as an integer declaration.

So to me, the lexical representation and its semantics are two
different things, and the language processor is responsible for
converting the lexical representation into some parse tree (or the
AST), or some other structure which can be executed, and performing
the actions as per the semantics.


On 9/26/07, Costello, Roger L. <costello@mitre.org> wrote:
> Hi Folks,
>
> Below are a few notes I put together concerning the text-only nature of
> XML. At the bottom of this message are a few questions that I would
> very much appreciate your thoughts on. /Roger
>
> ------------------------------------
> XML IS TEXT
>
> An XML document is comprised purely of text. That is, the contents of
> an XML document is just a string of characters. There are no integers
> in an XML document. There are no floating point values in an XML
> document. There are only characters.
>
> ------------------------------------
> EXAMPLE
>
> Here is a simple XML document. It would appear that the value of the
> <x> element is an integer:
>
>    <?xml version="1.0"?>
>    <x>23</x>
>
> However, that is not the case. The 23 represents two characters, 2 and
> 3.
>
> You can see that they are indeed characters by viewing the hex values
> of the XML document:
>
> http://www.xfront.com/hex-values-of-a-simple-XML-document.gif
>
> In the graphic you see that the hex values of 23 are x32 and x33, which
> corresponds to the character 2, and the character 3.
>
> Compare with an integer value 23; it's binary value is 00010111, which
> has a hex value 17.
>
> Thus, XML is just text. And you use a "text" editor to create an XML
> document.
>
> ------------------------------------
> MANIPULATING XML
>
> Consider manipulating an XML document using XSLT. Here is shown an XSLT
> statement which multiplies the value of the <x> element by the number
> 2:
>
>    <xsl:value-of select="x * 2"/>
>
> How can the two characters 23 be multiplied by an integer 2?
>
> Answer: the XSLT processor first converts the two characters into an
> integer:
>
>    Convert these two hex values: 32 33 into this hex value: 17
>
> After doing the conversion then the XSLT processor performs the
> multiplication.
>
> ------------------------------------
> DECLARING AN ELEMENT'S DATATYPE IN A SCHEMA
>
> Consider an XML Schema that declares the element <x> as an integer:
>
>    <element name="x" type="integer"/>
>
> This is not stating:
>
>    "The value of the element x in an XML instance document is an
> integer."
>
> Rather, it is stating:
>
>    "The value of the element x in an XML instance document may be
> converted to an integer."
>
> ------------------------------------
> QUESTIONS
>
> 1. Is the above accurate?
>
> 2. Is there such a thing as a document which contains both text and
> integers?
>
> 3. Do different platforms represent, say, integers differently? Is that
> why XML decided to be text-only?
>
> ------------------------------------
> Note: I found a very nice editor that enables you to view the hex
> version of a text file: PSPad at http://www.snapfiles.com/get/spad.html


-- 
Regards,
Mukul Gandhi


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS