473,406 Members | 2,217 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,406 software developers and data experts.

XmlReader and recursive descent parsers

I just wrote my second method that reads an XML stream with XmlReader
and spits out a instance of an object that represents the XML stream.
In effect, this was a simple recursive descent parser that uses the
XmlReader as a tokenizer.

Realizing this naturally led to the question: Are there any tools
which would let me supply a description of the domain semantics
(perhaps in XSD) and which would construct a parser shell that can
turn a (say) <Foo> element into an instance of a Foo object, leaving
me only the task of parsing the attributes and storing child elements
in the proper fields?

I did a few Google searches that didn't turn up anything, but that's
never very conclusive ....

--

www.midnightbeach.com
Nov 12 '05 #1
6 2407
Jon Shemitz wrote:
Realizing this naturally led to the question: Are there any tools
which would let me supply a description of the domain semantics
(perhaps in XSD) and which would construct a parser shell that can
turn a (say) <Foo> element into an instance of a Foo object, leaving
me only the task of parsing the attributes and storing child elements
in the proper fields?


Sounds like you are talking about XmlSerializer.

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.xmllab.net
http://blog.tkachenko.com
Nov 12 '05 #2
"Oleg Tkachenko [MVP]" wrote:
Realizing this naturally led to the question: Are there any tools
which would let me supply a description of the domain semantics
(perhaps in XSD) and which would construct a parser shell that can
turn a (say) <Foo> element into an instance of a Foo object, leaving
me only the task of parsing the attributes and storing child elements
in the proper fields?


Sounds like you are talking about XmlSerializer.


No, not quite. XmlSerializer will save and restore an object (if
you're lucky): I'm looking for a parser generator that knows about the
XML structure but that makes no assumptions about the data structure
you build from it.

--

www.midnightbeach.com
Nov 12 '05 #3
Jon Shemitz wrote:
No, not quite. XmlSerializer will save and restore an object (if
you're lucky): I'm looking for a parser generator that knows about the
XML structure but that makes no assumptions about the data structure
you build from it.


Aha, sort of "typed XmlReader". There were some talks before, but I
haven't heard of any implementattions yet. The problem is that the
benefits are still unclear - why do you need it?

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.xmllab.net
http://blog.tkachenko.com
Nov 12 '05 #4
"Oleg Tkachenko [MVP]" wrote:
Aha, sort of "typed XmlReader". There were some talks before, but I
haven't heard of any implementattions yet. The problem is that the
benefits are still unclear - why do you need it?


For much the same reasons that one uses a parser generator instead of
building a parser by hand: It takes less time to write, it takes less
time to debug, and it's easier to verify.

I spent hours getting my most recent XmlReader code to handle child
elements properly. Partly that was because my XmlWriter code was
putting a wholly unnecessary <contents></contents> layer around child
elements, but partly that was because I had trouble keeping track of
all the possible Next States. I kept running into assertion violations
or even infinite loops.

Not my happiest few hours!

--

www.midnightbeach.com
Nov 12 '05 #5
Jon Shemitz wrote:
For much the same reasons that one uses a parser generator instead of
building a parser by hand: It takes less time to write, it takes less
time to debug, and it's easier to verify.

I spent hours getting my most recent XmlReader code to handle child
elements properly. Partly that was because my XmlWriter code was
putting a wholly unnecessary <contents></contents> layer around child
elements, but partly that was because I had trouble keeping track of
all the possible Next States. I kept running into assertion violations
or even infinite loops.


I'm curious what API and behaviour would you expect from such "typed
XmlReader"?

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.xmllab.net
http://blog.tkachenko.com
Nov 12 '05 #6
"Oleg Tkachenko [MVP]" wrote:
I'm curious what API and behaviour would you expect from such "typed
XmlReader"?


Oh, there's a pretty wide range, there, I suppose. Something like
Coco/R's annotated grammar would make some sense - a way to add
arbitrary C# code at the points in the grammar where the generator
would create a method. That way, you could update the grammar (if you
didn't get it right the first time) and regenerate the parser without
losing all your actions.

I don't have the widest experience with parser generators - there
might be other schemes that make more sense - but Coco/R's is pretty
straightforward. Sure was better than Visual Parse's vile reduction
function.

--

www.midnightbeach.com
Nov 12 '05 #7

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

Similar topics

0
by: Phlip | last post by:
C++ newsgroupies: I wrote a parser to solve math expressions like "3.0 ^(4 - 5)", or "3 / 8". Below my sig is recursiveDescentParser.cpp, the test suite that drove the implementation of the...
6
by: Phlip | last post by:
C++ newsgroupies: I wrote a parser to solve math expressions like "3.0 ^(4 - 5)", or "3 / 8". It's bad luck to name an interface after its implementation. This file could have been...
0
by: Phlip | last post by:
C++ newsgroupies: I wrote a parser to solve math expressions like "3.0 ^(4 - 5)", or "3 / 8". Below my sig is test.h, the file containing a tiny test framework. Using it and Test-Driven...
9
by: seberino | last post by:
I'm a compiler newbie and curious if Python grammar is able to be parsed by a recursive descent parser or if it requires a more powerful algorithm. Chris
4
by: seberino | last post by:
I'm a compiler newbie and was curious if Python's language/grammar can be handled by a recursive descent parser. Well? Chris
18
by: Just Another Victim of the Ambient Morality | last post by:
Is pyparsing really a recursive descent parser? I ask this because there are grammars it can't parse that my recursive descent parser would parse, should I have written one. For instance: ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.