[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XML is text-only ... why?

  • From: "Mukul Gandhi" <gandhi.mukul@g...>
  • To: "Costello, Roger L." <costello@m...>
  • Date: Wed, 26 Sep 2007 23:05:10 +0530

Re:  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@m...> 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]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.