473,569 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I detect empty tags?

How do I detect empty tags if I have the DOM document?

For example: <br /> and <br></br>

I tried org.w3c.dom.Nod e.getFirstChild (), it returns null for both <br
/> and <br></br>
I also tried getNodeValue(), they both returns null also.

I know <br /> and <br></br> are the same from the xml spec. Is there
any way to tell the different syntax using DOM parser?

Thanks,
-John

Jul 20 '05 #1
13 2314
On 13 Apr 2005 18:23:59 -0700, "vega" <jo****@gmail.c om> wrote:
How do I detect empty tags if I have the DOM document?

For example: <br /> and <br></br>


You can't and you don't need to. In XML these are exactly
equivalent(sic) .

http://www.w3.org/TR/2004/REC-xml-20...#sec-starttags

"Empty-element tags MAY be used for any element which has no content,
whether or not it is declared using the keyword EMPTY. For
interoperabilit y, the empty-element tag SHOULD be used, and SHOULD
only be used, for elements which are declared EMPTY."
There may be a useful difference you can find in the element's
definition from DTD or schema - i..e. EMPTY You can access this by
either parsing it, or (more easily) by using a document parser that
understands schema and offers a more direct link to the relevant one.

This is the definition though, not the instance. It won't tell you if
the empty-element form of the tag in your document was used because
it's an EMPTY element, or just a non-empty element that happens to
have no content in this instance.
In general though, the way the document was serialised is not visible
to an XML application and even more importantly there is NO reason why
it needs to be. You just never need it.

If you do think you need it, then the chances are that you're in a
non-XML context, such as XHTML or RSS. Although these are ostensibly
XML protocols, they exist in an environment that's still rooted in the
HTML past. There may be valid reasons for still caring about things
that a purely XML context wouldn't need to.

Jul 20 '05 #2
<br/> and <br></br> are same according to XML spec.. I do not think
any compliant XML parser would treat these two ways differently. So I
think the XML parser cannot report this difference..

Just also curious, for what purpose this information is useful to
you..

Regards,
Mukul

"vega" <jo****@gmail.c om> wrote in message news:<11******* *************@z 14g2000cwz.goog legroups.com>.. .
How do I detect empty tags if I have the DOM document?

For example: <br /> and <br></br>

I tried org.w3c.dom.Nod e.getFirstChild (), it returns null for both <br
/> and <br></br>
I also tried getNodeValue(), they both returns null also.

I know <br /> and <br></br> are the same from the xml spec. Is there
any way to tell the different syntax using DOM parser?

Thanks,
-John

Jul 20 '05 #3
In article <b1************ *************@p osting.google.c om>,
Mukul Gandhi <mu**********@y ahoo.com> wrote:
<br/> and <br></br> are same according to XML spec.. I do not think
any compliant XML parser would treat these two ways differently. So I
think the XML parser cannot report this difference..
An XML parser can report what it likes, but it would usually be unwise
to write software that depended on the difference. For one thing,
passing the document through any common XML program might well change
it.

The XML Infoset does not distinguish between the two forms.
Just also curious, for what purpose this information is useful to
you..


Editor-like applications should preserve the user's preferred
formatting, and ideally so should any application that doesn't
completely alter the structure of the document.

-- Richard
Jul 20 '05 #4
* Richard Tobin
Just also curious, for what purpose this information is useful to
you..


Editor-like applications should preserve the user's preferred
formatting, and ideally so should any application that doesn't
completely alter the structure of the document.


Would <br><!-- metainformation comment --></br> be illegal according
to the spec?

--
Jon Haugsand
Dept. of Informatics, Univ. of Oslo, Norway, mailto:jo*****@ ifi.uio.no
http://www.ifi.uio.no/~jonhaug/, Phone: +47 22 85 24 92
Jul 20 '05 #5
Jon Haugsand wrote:
* Richard Tobin
Just also curious, for what purpose this information is useful to
you..


Editor-like applications should preserve the user's preferred
formatting, and ideally so should any application that doesn't
completely alter the structure of the document.

Would <br><!-- metainformation comment --></br> be illegal according
to the spec?


Das interessiert mich auch. Ich habe hier nachgeschaut:

http://www.w3.org/TR/xhtml1/#C_2

Dort heisst es man sollte <br /> bevorzugen (statt <br></br>) (xhtml)

und hier

http://www.w3.org/TR/1999/REC-html40...t.html#edef-BR

Hier heisst es, dass <br /> nicht erlaubt sei (html 4.01) (Start tag:
required, End tag: forbidden)
Jul 20 '05 #6
On 14 Apr 2005 15:12:57 +0200, Jon Haugsand <jo*****@ifi.ui o.no>
wrote:
Would <br><!-- metainformation comment --></br> be illegal according
to the spec?


Yes. (according to XML 1.0)
http://www.w3.org/TR/2004/REC-xml-20040204/#NT-content
"The representation of an empty element is either a start-tag
immediately followed by an end-tag, or an empty-element tag."

Note "immediatel y"

<br/> is equivalent to <br />
<br /> is equivalent to <br></br>

<br>[... anything ...]</br> is _not_ equivalent to <br></br>

Even <br> </br> (simple whitespace) is not empty content and thus is
invalid for an element defined as EMPTY
Of course in most cases this will be treated as valid, because <br />
is presumed to be an XHTML element and most XHTML gets handled by a
HTML parser, not an XML parser.

Jul 20 '05 #7


Of course in most cases this will be treated as valid, because <br />
is presumed to be an XHTML element and most XHTML gets handled by a
HTML parser, not an XML parser.
Except that if it gets handled by a real HTML parser it is valid but
equivalent to <br>> so typesets a > at the start of the new line.

See what onsgmls makes of:

<html><head><ti tle>a</title></head>
<body>
<br/><br>>
</body>
</html>
(BODY
AID IMPLIED
ACLASS IMPLIED
ASTYLE IMPLIED
ATITLE IMPLIED
ACLEAR TOKEN NONE
(BR
)BR
->
AID IMPLIED
ACLASS IMPLIED
ASTYLE IMPLIED
ATITLE IMPLIED
ACLEAR TOKEN NONE
(BR
)BR
->
)BODY
)HTML
C
David
Jul 20 '05 #8
On Thu, 14 Apr 2005 14:39:42 GMT, David Carlisle <da****@nag.co. uk>
wrote:
Except that if it gets handled by a real HTML parser


But is HTML SGML ? 8-) I accept your point for SGML certainly, but
HTML is a world-of-hacks no matter how you look at it.

Jul 20 '05 #9
On Thu, 14 Apr 2005, Andy Dingley wrote:
But is HTML SGML ? 8-)
The W3C say both yes and no. This has been discussed before, or
course: in the body of the HTML specification, they describe HTML as
an application of SGML, but then later on they rule-out certain
constructions when SGML didn't allow to be ruled out. That's the way
I understood the argument, anyway.
I accept your point for SGML certainly, but HTML is a world-of-hacks
no matter how you look at it.


Indeed. And XHTML/1,0 Appendix C continued that messy tradition.
Quite why so many newcomers aspire to just that, beats me.
Jul 20 '05 #10

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

Similar topics

2
3548
by: Aquarius2431 | last post by:
Hi!, I don't think I have posted to this group before. Have been using PHP on my webserver for a few months now and finding that I like it quite a bit. Here is a question that just occurred to me. I recently created a BBS (Bulletin Board Service) on my website where I allow people to post messages via a form. It just occurred to me that...
3
8877
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns a empty value instead of returning the browser type. Here is the line which i am using in my code and from manual: <?php echo $_SERVER; ?>
13
3386
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to <foo/>) From XHTML specification:
23
15570
by: Michel Bany | last post by:
I am trying to parse responseXML from an HTTP request. var doc = request.responseXML; var elements = doc.getElementsByTagName("*"); the last statement returns an empty collection when running from IE6. It returns the expected collection when running under Firefox or Mozilla. Anybody can explain ? Michel.
12
17086
by: Stefan Weiss | last post by:
Hi. (this is somewhat similar to yesterday's thread about empty links) I noticed that Tidy issues warnings whenever it encounters empty tags, and strips those tags if cleanup was requested. This is okay in some cases (such as <tbody>), but problematic for other tags (such as <option>). Some tags (td, th, ...) do not produce warnings when...
1
5364
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved completely/succsessfully on the client's computer before updating some metadata on the server (file downloaded date for instance) However, All examples i have tried,...
5
3668
by: wolf_y | last post by:
My question is simply: under what conditions will empty tags of the form <MOM></MOM> pass schema validation? Of course, the mirror question is: under what conditions will empty tags fail validation? The former seems to be an easier question to answer. XML files will arrive from around the world and must be schema validated before further...
10
3086
by: Barry L. Camp | last post by:
Hi all... hope someone can help out. Not a unique situation, but my search for a solution has not yielded what I need yet. I'm trying to come up with a regular expression for a RegularExpressionValidator that will allow certain HTML tags: <a>, <b>, <blockquote>, <br>, <i>, <img>, <li>, <ol>, <p>, <quote>, <ul>
11
3301
by: David | last post by:
Hi All, I am working on a script that is theoreticaly simple but I can not get it to work completely. I am dealing with a page spit out by .NET that leaves empty tags in the markup. I need a javascript solution to go behind and do a clean up after the page loads. The .NET will leave behind any combination of nested tags. Here is an...
0
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.