freelanceprogrammers.org Forum Index » XML / XSL
XML Rationality?
Joined: 11 Apr 2005
Posts: 3
XML Rationality?
On Apr 8, 2005 10:19 PM, Thomas J. Hruska
<shinelight@...> wrote:
>
>...
>
> Let`s say I want a numbered list in XML to contain data. The natural thing
> to do is to make the numbers be the tag identifiers as part of a parent
> group.
No, that isn`t natural at all. It implies that the DTD or schema will
have an infinite number of elements. Element type names are basically
pointers into the document type which is typically represented as a
DTD or schema. Numbers as element type names don`t make much more
sense than numbers as methods in an OOP programming language or
numbers as table names in a database.
>...
> (This is a really _simple_ example of my main scenario)
> <?xml version="1.0" standalone="yes"?>
> <World>
> <Widgets>
> <Count>15</Count>
> <1>...some data...</1>
> <2>...some data...</2>
> <3>...some data...</3>
> ...You get the idea...
> </Widgets>
> </World>
What would be wrong with:
<Widgets>
<Count>15</Count>
<item>...some data...</item>
<item>...some data...</item>
<item>...some data...</item>
</Widgets>
Then you would address Widets/Count/item[1] or Wdgets/Count/item[2] etc.
Why can`t XML have numbers as identifiers? Just because XML`s
identifier syntax is very conventional and similar to programming
languages, databases, HTML, SGML, and most other languages.
Paul Prescod
Joined: 11 Apr 2005
Posts: 3
XML Rationality?
On Apr 8, 2005 10:19 PM, Thomas J. Hruska
<shinelight@...> wrote:
>
>...
>
> Let`s say I want a numbered list in XML to contain data. The natural thing
> to do is to make the numbers be the tag identifiers as part of a parent
> group.
No, that isn`t natural at all. It implies that the DTD or schema will
have an infinite number of elements. Element type names are basically
pointers into the document type which is typically represented as a
DTD or schema. Numbers as element type names don`t make much more
sense than numbers as methods in an OOP programming language or
numbers as table names in a database.
>...
> (This is a really _simple_ example of my main scenario)
> <?xml version="1.0" standalone="yes"?>
> <World>
> <Widgets>
> <Count>15</Count>
> <1>...some data...</1>
> <2>...some data...</2>
> <3>...some data...</3>
> ...You get the idea...
> </Widgets>
> </World>
What would be wrong with:
<Widgets>
<Count>15</Count>
<item>...some data...</item>
<item>...some data...</item>
<item>...some data...</item>
</Widgets>
Then you would address Widets/Count/item[1] or Wdgets/Count/item[2] etc.
Why can`t XML have numbers as identifiers? Just because XML`s
identifier syntax is very conventional and similar to programming
languages, databases, HTML, SGML, and most other languages.
Paul Prescod
Joined: 08 Feb 2005
Posts: 8
XML Rationality?
Hi Thomas
> Let`s say I want a numbered list in XML to contain data. The natural thing
> to do is to make the numbers be the tag identifiers as part of a parent
> group.
So what happens when you need to re-order the list?
In general, you wouldn`t mark up a list item with its position in the
list, you would allow the number to be generated in the presentation
layer.
The only exeption to this that I can think off is in legal-type
documents where, once negotiations have started on a document, the
clause numbers *must not* change. In which case I would almost
certainly add an attribute to contain the number value.
What exactly are you trying to achieve?
-Melanie
Joined: 12 Apr 2005
Posts: 2
XML Rationality?
Hello,
On Sat, 09 Apr 2005 01:19:02 -0400
"Thomas J. Hruska" <shinelight@...> wrote:
> ...
>
> Let`s say I want a numbered list in XML to contain data. The natural
> thing to do is to make the numbers be the tag identifiers as part of a
> parent group.
It depends. For me it`s very unnatural. Numbers shouldn`t be in XML,
they are to be calculated by a visualisation/transformation agent.
> Nope. Not allowed. Here`s an example of what I`m
> talking about:
>
> (This is a really _simple_ example of my main scenario)
> <?xml version="1.0" standalone="yes"?>
> <World>
> <Widgets>
> <Count>15</Count>
> <1>...some data...</1>
> <2>...some data...</2>
> <3>...some data...</3>
> ...You get the idea...
> </Widgets>
> </World>
>
> ...
>
> What _was_ the W3C (ir)rationality behind the idea of requiring element
> names to start with a letter?
One of the design goals for XML was "XML shall be compatible with SGML",
and SGML works so.
More, having a programming background, it`s quite natural to avoid
literals which starts with a number. It`s because allowing this limits
flexinility in different tools.
For example, consider the following XPaths:
aaa[bbb]
aaa[1]
The former selects elements "aaa" which have a child "bbb", the latter
selects the first element "aaa".
If we allow "1" as an element name, how to interpret the following:
/World/Widgets[1]
Is it "Widgets" which have a child "1" or is it the first "Widget"?
> ...
>
> Thomas J. Hruska
> shinelight@...
--
Oleg Paraschenko olpa@ http://bitplant.de/ - IT Services company
SGML/XML/Content management/WWW/Databases/Win32/Plug-ins/Scripts
http://uucode.com/blog/ Generative Programming, XML, TeX, Scheme
Joined: 13 Apr 2005
Posts: 5
XML Rationality?
At 12:35 AM 4/12/2005 +0400, Oleg A. Paraschenko writeth:
> If we allow "1" as an element name, how to interpret the following:
>
>/World/Widgets[1]
>
> Is it "Widgets" which have a child "1" or is it the first "Widget"?
Neither. It makes more sense (even programmatically speaking) to return
the first group of Widgets in that scenario. If I want child `1` (i.e. the
Widget named `1`), I ask the XML parser I`m using for:
World/Widgets/1
Asking for a specific child of a parent node never makes any sense, IMO
(you would probably end up with "George" data instead of Widget data). For
all intents and purposes, from my perspective, XML is centered around
string-based lookups and returns string-based data (which may later be
converted to other types, but its core type is a string to string mapping -
in C++ STL terms, XML is, more or less, a multimap<string, string>).
Melanie: You hit the head on the nail - I have an ordered list of elements
and it has to stay ordered regardless of how the XML parser loads it into
memory. Unfortunately, I can`t use attributes for the ID because that
increases searching complexity to at least O(N^2) for finding the next
ordered component (versus O(N) with unique names).
Besides, I was just asking why something is the way it is - not really
looking for comments on why it doesn`t make sense to you - it makes perfect
sense to me and my scenario (system performance and nubmer-based ids as
element names to achieve the desired performance). Paul gave me the
answer: SGML compatability. No one I know uses SGML...and have only heard
of it in three places - here in response to my question, the W3C standard,
and one forum message saying SGML isn`t all that its cracked up to be. To
me, from my perspective, the SGML restriction is lame and unnecessary
because out of the several thousand people I know, I don`t know a single
person of that group who has ever used SGML (let alone heard of it), but
I`m surely not the only one out there who thinks that data elements can be
numbered because a number can be simply viewed as a string too.
Anyway, I think this conversation is at an end. Those who are trying to
change my way of thinking about XML won`t succeed. I`ve always thought in
terms of string manipulation and XML is an exercise in string manipulation
regardless of DTDs and schemas and other unnecessary hoopla that I barely
care about (all my XML is standalone).
Thomas J. Hruska
shinelight@...
Shining Light Productions
Home of the Nuclear Vision scripting language and ProtoNova web server.
http://www.slproweb.com/
Joined: 11 Apr 2005
Posts: 3
XML Rationality?
(reviving an old thread just because I notice I`ve been misquoted)
On 4/13/05, Thomas J. Hruska <shinelight@...> wrote:
>
> ...
>
> Asking for a specific child of a parent node never makes any sense, IMO
> (you would probably end up with "George" data instead of Widget data). For
> all intents and purposes, from my perspective, XML is centered around
> string-based lookups and returns string-based data (which may later be
> converted to other types, but its core type is a string to string mapping -
> in C++ STL terms, XML is, more or less, a multimap<string, string>).
Nobody can force you to think of XML otherwise but we can tell you
that the hundred or so people who were involved with the
standardization of XML *DID NOT THINK* of it that way. XML was
designed for documents and therefore ordered data is the *default
mode*, not something that you hack by making element types based upon
numbers.
> Melanie: You hit the head on the nail - I have an ordered list of elements
> and it has to stay ordered regardless of how the XML parser loads it into
> memory.
No XML parser will lose the order of loaded XML data. I`ve used dozens
of them and none of them lose order of elements. That`s because XML
elements are _inherently ordered_. They are not
maps/dictionaries/structures. XML attribute lists are maps. XML
element contents are not.
>...
> Besides, I was just asking why something is the way it is - not really
> looking for comments on why it doesn`t make sense to you - it makes perfect
> sense to me and my scenario (system performance and nubmer-based ids as
> element names to achieve the desired performance).
I guarantee you won`t increase your performance by fighting against
the implementation model of all existing XML parsers. For example,
most of them cache (intern) element type names. So if you have a
hundred widgets in a row they only cache the element type name
"widget" once. But if you had "widget1", "widget2", ... to "widget100"
then the interning woudl be foiled.
> ... Paul gave me the answer: SGML compatability.
I did not say that. I said:
"XML`s identifier syntax is very conventional and similar to
programming languages, databases, HTML, SGML, and most other
languages."
If there had been something wrong with SGML`s definition of identifier
then XML could have changed it. But SGML`s definition is the same as
every other language`s definition:
Do your programming language allow "1" is a legal variable name? Does
your database allow "1" as a column name? XML elements type names are
identifiers like method names, column names, table names, etc. It is
totally redundant to give elements a number based on their position
because your XML parser already tells you the position of the
elements.
Take the following XML document:
<?xml-stylesheet href="order.xsl" type="text/xsl"?>
<widgets>
<widget>one</widget>
<widget>two</widget>
<widget>three</widget>
<widget>four</widget>
<widget>five</widget>
<widget>six</widget>
</widgets>
Now let`s apply a computer program to it. In this case it is XSLT but
you could do the same with Java, or Python or any other language.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<xsl:apply-templates/>
</html>
</xsl:template>
<xsl:template match="widget">
<p><xsl:number/> .
<xsl:value-of select="."/></p>
</xsl:template>
</xsl:stylesheet>
You`ll find that the output is:
1 . one
2 . two
3 . three
4 . four
5 . five
6 . six
The order is preserved despite the fact that no numbers are in the XML.
A Java program using SAX or DOM would behave the same.
Paul Prescod
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







