473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to differentiate between <XX></XX> and <XX/> with SAX

Is there a simple and determinist way to make the difference
between the 2 sequences:

<XX></XX>

and

<XX/>

The EndElement callback does not provide this information.

Thanks,
Pascal.
Jul 20 '05 #1
13 2459
dp*****@yahoo.fr wrote:
Is there a simple and determinist way to make the difference
between the 2 sequences:

<XX></XX>

and

<XX/>
No. Their meaning is exactly the same. Why do you think you need that?
The EndElement callback does not provide this information.

Jul 20 '05 #2
Rolf Magnus wrote:
dp*****@yahoo.fr wrote:

Is there a simple and determinist way to make the difference
between the 2 sequences:

<XX></XX>

and

<XX/>

No. Their meaning is exactly the same. Why do you think you need that?


Doesn't the first sample have an empty text() node as first child, and
the second doesn't ?

Franck,e-

The EndElement callback does not provide this information.


Jul 20 '05 #3
In article <41***********************@news.free.fr>,
Franck Guillaud <f_**************@free.fr> wrote:
<XX></XX>

<XX/>
Doesn't the first sample have an empty text() node as first child, and
the second doesn't ?


No.

(XML itself doesn't define any such thing as a "text node". The
Infoset has character information items, and there aren't any of them
in either case. The XPath data model doesn't have a text node in either
case, and SAX parsers do not call the characters method.)

-- Richard
Jul 20 '05 #4
Rolf Magnus wrote:

No. Their meaning is exactly the same. Why do you think you need that?


Ok, everywhere, I read that they are the same.
But this is only true for XML, not for HTML, and even it if was
true for HTML, it is still not true due to the way browsers interpret it.

What I need is to parse manually written HTML.
In HTML, <BR/> is interpreted differently than <BR></BR>.

So, I have to basic reasons to do this:

- I need it, the parser must make the difference, because
it must ouput tag that it does not process like they were entered
in order for the ouput to be correctly interpreted.

- Even if it was not needed due to a technical reason, if the
developper who wrote the HTML page decided that it is <XX/>, i
prefer to output <XX/> rather than the other form. So that the
developper can easily read the output of my program, and do not have
to wonder about some "strange" conversion.

Summary;

We do no live in a perfect world, with perfect standard perfectly
implemented by perfect developper. So we need a "stable" way to
do the difference. I like standards very much (I have a networking
background, you know ISO, IETF, IEEE, ATM FORUM, FR FORUIM, EIA, etc etc
....), but I live in a non standard world. I must adapt to survive :-)

Thanks for your help.
Pascal.

Jul 20 '05 #5

Ok, everywhere, I read that they are the same.
But this is only true for XML, not for HTML, and even it if was
true for HTML, it is still not true due to the way browsers interpret it.
well for HTML (but this is after all an XML newsgroup) the situation is
completely different.
<BR/> and <BR></BR>
are _both_ syntax errors ( /> is always a syntax error in HTML, and BR
has no end tag as it is declared EMPTY in the HTML DTD, so </BR> is also
an error)

Of course a browser may or may not have some lax silent error recovery
from either of these situtations but in any case the behaviour will be
browser specific.

- Even if it was not needed due to a technical reason, if the
developper who wrote the HTML page decided that it is <XX/>, i
prefer to output <XX/> rather than the other form.


So long as you are clearly writing HTML rather than XML there's nothing
wrong with you doing that. XSLT for example, if writing html can not
distinguish the inputs of <BR/> and <BR></BR> as the input is XML and
these are the same, but in either case an "identity" transform will
produce the HTML syntax
<BR>
if the html output method is being used (which it is by default if the
top level output element is <html>.

David

Jul 20 '05 #6
Pascal Dufour wrote:
Rolf Magnus wrote:
>
> No. Their meaning is exactly the same. Why do you think you need that?
>
Ok, everywhere, I read that they are the same.
But this is only true for XML, not for HTML, and even it if was
true for HTML, it is still not true due to the way browsers interpret it.

What I need is to parse manually written HTML.
In HTML, <BR/> is interpreted differently than <BR></BR>.


you can't parse html with an xml parser ; however, you can parse html
with an sgml parser ; additionally, you can use a tool that converts
html in xml (with best effort), like Cyber Neko HTML Parser
http://www.apache.org/%7Eandyc/neko/doc/html/

So, I have to basic reasons to do this:

- I need it, the parser must make the difference, because
it must ouput tag that it does not process like they were entered
in order for the ouput to be correctly interpreted.
there's something quite confusing : you're talking about parsing like
outputing ; these 2 processes are totally opposite : parsing gives
access to a data model, and serializing (i prefer this term) renders
this data model to an xml characters form (file, char flow...)

you can't act on the xml data model because it is governed by a set of
stable specifications, but you can act on the serialization ; for this
purpose, formatter tools often provide a set of options that allow to
tune the output ; you can also write your own formatter

- Even if it was not needed due to a technical reason, if the
developper who wrote the HTML page decided that it is <XX/>, i
prefer to output <XX/> rather than the other form. So that the
developper can easily read the output of my program, and do not have
to wonder about some "strange" conversion.

Summary;

We do no live in a perfect world, with perfect standard perfectly
implemented by perfect developper. So we need a "stable" way to
do the difference. I like standards very much (I have a networking
background, you know ISO, IETF, IEEE, ATM FORUM, FR FORUIM, EIA, etc etc
...), but I live in a non standard world. I must adapt to survive :-)

Thanks for your help.
Pascal.

--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
Jul 20 '05 #7
David Carlisle <da****@nag.co.uk> writes:
XSLT for example, if writing html can not
distinguish the inputs of <BR/> and <BR></BR> as the input is XML and
these are the same,


Actually, in XML, the notion "element" is not an abstract one,
but a concrete non-terminal symbol of the syntax.

Therefore, as elements, the element "<br/>" and the element
"<br></br>" are two /different/ elements, just as "<br/>" also
is a different element than "<br />".

You might say, that they have the same element type, the same
contents and the same number, names and value of attributes
(here: none). Or, possibly, that they have the same
"infoset", but the infoset specification is not part of the
XML specification.
Jul 20 '05 #8
In article <yg*************@penguin.nag.co.uk>,
David Carlisle <da****@nag.co.uk> wrote:

% are _both_ syntax errors ( /> is always a syntax error in HTML, and BR

Actually, it's not, although its meaning is not the same as in XML. <br />
means the same as <br>>.
--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #9
Actually, it's not, although its meaning is not the same as in XML. <br />
means the same as <br>>.


Ooops sorry I was thinking that was turned off in HTML's SGML decl, but
apparently not. Still (most:-) of my point holds, in fact that means
that the situation is worse than I indicated: if you rely on <br/>
working in the browser after sending the file with an html mime type you
are not just relying on lax error recovery, you are relying on
non-conformant HTML parsing.
David
Jul 20 '05 #10
Philippe Poulard wrote:
So, I have to basic reasons to do this:

- I need it, the parser must make the difference, because
it must ouput tag that it does not process like they were entered
in order for the ouput to be correctly interpreted.

there's something quite confusing : you're talking about parsing like
outputing ; these 2 processes are totally opposite : parsing gives
access to a data model, and serializing (i prefer this term) renders
this data model to an xml characters form (file, char flow...)


No, what I meant is:

A - Developpers write a file formatted in a certain way
B - I parse the file and create an in-memory representation (a tree)
C - I process the tree and for certain tag I replace them with some data
D - I put the tree back in a textual form.

If during B I loose the information on the format used in phase A, I
can not reproduce it in D.

So if

- In A i have <XX/>
- in B I do not know weither it is <XX/> or <XX></XX>
- C ... don't play a role in this discussion
- In D I must do an arbitrary choice for the output (serialisation).

This is true even if we forget HTML.


Jul 20 '05 #11
"Stefan Ram" <ra*@zedat.fu-berlin.de> wrote in message
news:XM*********************@ram.dialup.fu-berlin.de...
Actually, in XML, the notion "element" is not an abstract one,
but a concrete non-terminal symbol of the syntax.
Mr. Ram, I think your conclusions regarding the term "element" are
inconsistent with usage
throughout the XML spec.
Therefore, as elements, the element "<br/>" and the element
"<br></br>" are two /different/ elements, [snip]
What do you mean by different? Do you mean the two forms denote elements
that have different structures? This is the notion of "different" that is
at the heart of the preceding discussion. The definition of "element"
clearly shows that <br/>" and "<br></br>" are two forms that each denote a
single (empty) element. This equivalence is stated explicitly:

"The representation of an empty element is either a start-tag immediately
followed by an end-tag, or an empty-element tag."
just as "<br/>" also
is a different element than "<br />".


Per the spec, whitespace between the element name and trailing slash is not
significant:

[3] S ::= (#x20 | #x9 | #xD | #xA)+
[5] Name ::= (Letter | '_' | ':') (NameChar)*
[44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'

/kmc

Reference: "Extensible Markup Language (XML) 1.0 (Third Edition)"
http://www.w3.org/TR/REC-xml

Jul 20 '05 #12
"Keith M. Corbett" <km*@world.std.com> writes:
Therefore, as elements, the element "<br/>" and the element
"<br></br>" are two /different/ elements, [snip]What do you mean by different?


Extensionally different, that is:

An element is a certain sequence of Unicode characters. This
is specified by the XML-syntax (BNF).

Two elements differ if they differs as such sequences.
Do you mean the two forms denote elements
that have different structures?
In XML, you do not /denote/ elements. You /write/ elements.

An element is the actual sequence of characters, e.g., "<X/>"
/is/ an element, it does not /denote/ an element. (An element
might /denote/ something, like a book or a notion - depending
on the XML application.)

Let me use a comparison to make the notions clear: In C, the
literal "02" and the literal "002" are two /different/ literals,
even though they /denote/ the same value. The XML elements
are like those literals, not like the values.

This is the notion of "different" that is
at the heart of the preceding discussion. The definition of "element"
clearly shows that <br/>" and "<br></br>" are two forms that each denote a
single (empty) element.
These are indeed two forms. However, they do not /denote/
(empty) elements, the /are/ empty elements. (Just as "2" in C
does not /denote/ a literal, but /is/ a literal [and /denotes/
a value].)
This equivalence is stated explicitly:
"The representation of an empty element is either a start-tag immediately
followed by an end-tag, or an empty-element tag."


Both /are/ elements according to the definition:

[39] element ::= EmptyElemTag | STag content ETag

The part you quoted seems to intend to state that, e.g.,
both "<X></X>" and "<X/>" are empty elements. It does not
say, that they are the same element.
just as "<br/>" also
is a different element than "<br />".

Per the spec, whitespace between the element name and trailing slash is not
significant:
[3] S ::= (#x20 | #x9 | #xD | #xA)+
[5] Name ::= (Letter | '_' | ':') (NameChar)*
[44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'


What you quote here, defines "S" (white space) and then
uses this definition to define "EmptyElemTag". It does not
state that this is "insignificant". (An XML application
might choose to consider it to be insignificant, what
surely nearly all XML applications do.)
Jul 20 '05 #13
In article <el********************@ram.dialup.fu-berlin.de>,
Stefan Ram <ra*@zedat.fu-berlin.de> wrote:
Let me use a comparison to make the notions clear: In C, the
literal "02" and the literal "002" are two /different/ literals,
even though they /denote/ the same value. The XML elements
are like those literals, not like the values.


The XML spec itself does not have this distinction. It describes the
syntax, and in a few places says that things are insignificant, though
it does not attempt to be exhaustive about this. For example, it
says that the order of attributes is insignificant, but does not
mention whether the order of elements is significant.

The <x/> and <x></x> forms are syntactically different, and it may be
useful for some applications to preserve this difference for human
convenience, but applications are intended to treat them as
semantically equivalent, and this is explicit for applications layered
on the Infoset, which does not distinguish between the two syntactic
forms.

That seems to be enough: I don't see any point discussing whether they
are "the same element", or whether <x/> is an element or denotes one.
I'm sure you could come up with a consistent story either way, and
neither would tell us anything we don't already know.

-- Richard
Jul 20 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
59
by: Haines Brown | last post by:
I've not had a clear definition in my mind of "citation," and so have avoided it. For example, if I suggest that the reputation of the New York Times has suffered, is that a citation? I suppose...
4
by: bengee | last post by:
Hi First off - by the word "anchor" i DON'T mean a link, i.e. <a></a> tags I'm trying to position a <select> box inside a <div>. I can use relative positioning to set where the box should...
2
by: Buck Turgidson | last post by:
I want to have a css with 2 PRE styles, one bold with large font, and another non-bold and smaller font. I am new to CSS (and not exactly an expert in HTML, for that matter). Is there a way to...
11
by: Jamie Burns | last post by:
Hello, I just did a simple benchmark: for (xx=0;xx<100000;xx++) { rDerived* derived = dynamic_cast<rDerived*>(object); if (derived) derived->setValue(message.data.messageSetInt.value); } ...
23
by: Loony | last post by:
I have got a code like this in HTML section in ASP file which includes javascript file! The script works under MS IE but doesn't with Firefox! Can anybody tell me what is wrong? <HTML>...
11
by: Richard Maher | last post by:
Hi, I have read many of the copius entries on the subject of IE performance (or the lack thereof) when populating Select Lists. I don't mind the insert performance so much, (I get 100x120byte...
4
MrPickle
by: MrPickle | last post by:
What's the difference between the two? They both appear to do the same thing but if they both just did the same thing then why have 2 things to do 1 job?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.