473,378 Members | 1,451 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,378 software developers and data experts.

XML parsing: no EndElement for combined start/end tags

I thought each XmlNodeType.Element has a matching
XmlNodeType.EndElement. But, this does not occur when the XML file
has the following:

<example attr1="1" attr2="2" />

Even though this is syntactically the same as the following, which
does show the EndElement:

<example attr1="1" attr2="2">
</example>

You may be thinking, "duh, that's what the file shows", but in IE,
both cases are rendered as the single following line. They really are
supposed to be exactly the same. Is the XML reader broken?

Zytan

Apr 3 '07 #1
8 6376
Zytan,

Have you checked the files themselves in say, notepad? IE applys a
transformation on any XML that doesn't already have one applied to it to
produce the interactive HTML view that you see (with the collapsing
elements, etc, etc).

Your XML files should be coming out correctly. If not, can you show the
code that you are using to generate them?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Zytan" <zy**********@gmail.comwrote in message
news:11**********************@l77g2000hsb.googlegr oups.com...
>I thought each XmlNodeType.Element has a matching
XmlNodeType.EndElement. But, this does not occur when the XML file
has the following:

<example attr1="1" attr2="2" />

Even though this is syntactically the same as the following, which
does show the EndElement:

<example attr1="1" attr2="2">
</example>

You may be thinking, "duh, that's what the file shows", but in IE,
both cases are rendered as the single following line. They really are
supposed to be exactly the same. Is the XML reader broken?

Zytan

Apr 3 '07 #2
Have you checked the files themselves in say, notepad?

Yes. This is how I confirmed that what I mention in the above post is
happening. Those are the results of what notepage shows, the actual
text file itself.
IE applys a
transformation on any XML that doesn't already have one applied to it to
produce the interactive HTML view that you see (with the collapsing
elements, etc, etc).
Yes, and this is where I noticed that IE decides that the two-line
case is identical to the one-line case, which the XML standard
indicates is true, also. Thus, an XML parser should correctly show
that BOTH start tag and end tag exists, regardless of the underlying
text-coding.
Your XML files should be coming out correctly. If not, can you show the
code that you are using to generate them?
I am not creating the XML files, but I have shown the code above as a
small example to show to exactly what the XML files are like. The
problem is not in the creation, and wondering why IE makes them look
different. IE 'standardizes' them in that it shows what the file
logically stands for, regardless of the underlying text-code, to make
it easy to read (good job, IE). The problem is that why does IE parse
them correctly, according to the standard, but the .NET framework does
not? So much is based on XML files that I am astounded that this
issue has not been raised. I have start tag + end tags in one line of
text code, and .NET is telling me no end tag (EndElement) exists!

Zytan
Apr 3 '07 #3
Zytan,

You are going to have to provide a piece of code to show what you are
saying. Personally, I don't see it as an issue, as the infoset has no
concept of what an end tag is. That's something that is up to how you
represent the infoset (and the infoset does not have to be represented as a
text file, as WCF proves).

If you could provide the files that you are reading, and the code you
are using to read them, it would help greatly.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Zytan" <zy**********@gmail.comwrote in message
news:11*********************@o5g2000hsb.googlegrou ps.com...
> Have you checked the files themselves in say, notepad?

Yes. This is how I confirmed that what I mention in the above post is
happening. Those are the results of what notepage shows, the actual
text file itself.
>IE applys a
transformation on any XML that doesn't already have one applied to it to
produce the interactive HTML view that you see (with the collapsing
elements, etc, etc).

Yes, and this is where I noticed that IE decides that the two-line
case is identical to the one-line case, which the XML standard
indicates is true, also. Thus, an XML parser should correctly show
that BOTH start tag and end tag exists, regardless of the underlying
text-coding.
> Your XML files should be coming out correctly. If not, can you show
the
code that you are using to generate them?

I am not creating the XML files, but I have shown the code above as a
small example to show to exactly what the XML files are like. The
problem is not in the creation, and wondering why IE makes them look
different. IE 'standardizes' them in that it shows what the file
logically stands for, regardless of the underlying text-code, to make
it easy to read (good job, IE). The problem is that why does IE parse
them correctly, according to the standard, but the .NET framework does
not? So much is based on XML files that I am astounded that this
issue has not been raised. I have start tag + end tags in one line of
text code, and .NET is telling me no end tag (EndElement) exists!

Zytan


Apr 3 '07 #4
Zytan <zy**********@gmail.comwrote:
I thought each XmlNodeType.Element has a matching
XmlNodeType.EndElement. But, this does not occur when the XML file
has the following:

<example attr1="1" attr2="2" />
No. You only have a start element node, but the element is empty. You
should use XmlReader.IsEmptyElement to check this condition.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 3 '07 #5
I thought each XmlNodeType.Element has a matching
XmlNodeType.EndElement. But, this does not occur when the XML file
has the following:
<example attr1="1" attr2="2" />

No. You only have a start element node, but the element is empty. You
should use XmlReader.IsEmptyElement to check this condition.
Oh, so this is start tag without an end tag, and is normal. That
means the name 'start tag' is extremely misleading. It also means
that IE's reformatting of the XML file to show it more clearly (which
I like), is, in fact, wrong, since it's removing end tags (for
elements that have nothing in them, which are, I guess, empty
elements). Aalthough, I guess, no one really cares.

But, this answers my concern. It was no big deal, anyway, since for
all my empty elements, I wasn't expecting to get anything before I run
into the end tag, anyway, so the fact that it just never comes is not
really an issue.

Zytan

Apr 4 '07 #6
Zytan,
>
You are going to have to provide a piece of code to show what you are
saying. Personally, I don't see it as an issue, as the infoset has no
concept of what an end tag is. That's something that is up to how you
represent the infoset (and the infoset does not have to be represented as a
text file, as WCF proves).

If you could provide the files that you are reading, and the code you
are using to read them, it would help greatly.
Sorry, Nicholas, I think you were just missing the what I was trying
to explain, and yeah, code would clear up that explanation, but Jon
has answered my question, please see his post, and you'll know just
what I was talking about, and what was bothering me. C#'s XML parsing
was working exactly as it should. It was the idea that an empty
element only has a start tag, and no end tag (who would have thought?
doesn't every start have an end?), that was bothering me.

Thanks for your replies,

Zytan

Apr 4 '07 #7
This bit me the first time I used XmlReader, too. I also made the
assumption that <node></nodeand <node/would behave the same in
terms of start/end tags (although perhaps the latter would be flagged
as empty at the same time to mark the subtle difference). Of course,
sample data soon burned me. I guess I'm just saying that you aren't
alone in getting a little misled by this, but the fix is fortunately
very easy (as per Jon's post).

Marc

Apr 4 '07 #8
This bit me the first time I used XmlReader, too. I also made the
assumption that <node></nodeand <node/would behave the same in
terms of start/end tags (although perhaps the latter would be flagged
as empty at the same time to mark the subtle difference). Of course,
sample data soon burned me. I guess I'm just saying that you aren't
alone in getting a little misled by this, but the fix is fortunately
very easy (as per Jon's post).

Marc
Thank you for your story, Marc. I think the confusion is the
terminology. Since when does a 'start' not have an 'end'? Also, IE
confuses the issue since it removes end tags from empty elements that
are made from a start tag and an end tag with nothing inbetween, when
it displays XML, so that led me to believe that they were the same, as
well.

Zytan

Apr 5 '07 #9

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

Similar topics

2
by: Noyb | last post by:
I've set up a news links section using the RSS parsing tutorial found here: http://www.sitepoint.com/article/560 Everything works great but depending on the feed source there may be 3 news links...
5
by: Wes Batson | last post by:
Hi, I am using SAX parsing and I need to get the information between the tags. I have narrowed the problem down to my characters() method in the DefaultHandler class. Here is my code: public...
0
by: Naren | last post by:
I have an XML like the one below. I am using SAX parsing and I need to get the information between the tags of the Email element. First i try to access the content and print it out and it gives...
1
by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP...
4
by: ralphNOSPAM | last post by:
Is there a function or otherwise some way to pull out the target text within an XML tag? For example, in the XML tag below, I want to pull out 'CALIFORNIA'. ...
11
by: kenneth | last post by:
I just ran across this. #1 <DBColumn> 1 </DBColumn> #2 <DBColumn> </DBColumn> The data for #1 will be parsed and returned as " 1 ". I get a sequence of...
5
by: amjadcsu | last post by:
I am a newbie in python I am trying to parse a xml file and write its content in a txt file. The txt contains null elements. Any reason what iam doing wrong here Here is the code that i wrote...
8
by: Bob Bedford | last post by:
Hi all, I've to read and parse an XML file to save the datas in a database. Unfortunately it appens that the datas are wrong. I mean it seems they are not well readed...sometimes only part of...
3
by: GazK | last post by:
I have been using an xml parsing script to parse a number of rss feeds and return relevant results to a database. The script has worked well for a couple of years, despite having very crude...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.