[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

rexml exceptions

Eric Will

9/30/2008 2:57:00 AM

Is there any way to get any useful data out of REXML::ParseException
when you're working on a String? It never sets @position or @line or
anything. I need to figure out exactly where the error-causing tag
starts, and save it.

Any ideas?

-- rakaur

15 Answers

Mark Thomas

9/30/2008 1:58:00 PM

0

On Sep 29, 10:56 pm, Eric Will <rak...@malkier.net> wrote:
> Is there any way to get any useful data out of REXML::ParseException  
> when you're working on a String? It never sets @position or @line or  
> anything. I need to figure out exactly where the error-causing tag  
> starts, and save it.
>
> Any ideas?

Out of curiosity, I tried libxml. It has nice error messages:

foo.xml:3:
parser error :
Opening and ending tag mismatch: title line 3 and txitle
<title>Foo</txitle>
^

but they go to stdout. You can capture them by registering an error
handler. Sample code:

parser = XML::Parser.new
parser.filename = "foo.xml"

msgs = []
XML::Parser.register_error_handler lambda { |msg| msgs << msg }

begin
parser.parse
rescue Exception => e
puts "Error: #{msgs}"
end

-- Mark.

Eric Will

9/30/2008 3:43:00 PM

0

On Tue, Sep 30, 2008 at 9:59 AM, Mark Thomas <mark@thomaszone.com> wrote:
> Out of curiosity, I tried libxml. It has nice error messages:
>
> foo.xml:3:
> parser error :
> Opening and ending tag mismatch: title line 3 and txitle
> <title>Foo</txitle>
> ^
>
> but they go to stdout. You can capture them by registering an error
> handler. Sample code:
>
> parser = XML::Parser.new
> parser.filename = "foo.xml"
>
> msgs = []
> XML::Parser.register_error_handler lambda { |msg| msgs << msg }
>
> begin
> parser.parse
> rescue Exception => e
> puts "Error: #{msgs}"
> end

Interesting. I was thinking about doing libxml anyway. I do not like REXML.

Thanks.

> -- Mark.

-- rakaur

Eric Will

9/30/2008 4:46:00 PM

0

Actually, this isn't working for me. I'm using the SAX parser, and it
just calls Listener#on_parser_error with a string. Not helping me.

Mark Thomas

9/30/2008 5:37:00 PM

0

On Sep 30, 12:46 pm, Eric Will <rak...@malkier.net> wrote:
> Actually, this isn't working for me. I'm using the SAX parser, and it
> just calls Listener#on_parser_error with a string. Not helping me.

Why would you want to do that? You already have the XML as a string.
The only reason to put up with the awful interface and extra
complexity of SAX would be if your file doesn't fit into memory. And I
don't think the SAX interface to libxml is as complete/robust yet as
the DOM interface.

Go with the DOM interface. With libxml it's plenty fast.

-- Mark.

Eric Will

9/30/2008 6:09:00 PM

0

My situation requires SAX, unfortunately.

I need to parse and react to each tag as in comes in. If there's a
broken one, all tags up to the broken one must be processed, and the
broken one must be stored. I cannot do this in DOM, because if there's
an error, DOM will not process anything.

Eric Will

9/30/2008 6:51:00 PM

0

Also, I don't think those error messages can help me location the
position in the string of the bad XML. They're pretty, for sure, but
not very useful to anyone but a human.

Mark Thomas

9/30/2008 6:52:00 PM

0

On Sep 30, 2:09 pm, Eric Will <rak...@malkier.net> wrote:
> My situation requires SAX, unfortunately.
>
> I need to parse and react to each tag as in comes in. If there's a
> broken one, all tags up to the broken one must be processed, and the
> broken one must be stored. I cannot do this in DOM, because if there's
> an error, DOM will not process anything.

If you can receive an entire document at a time, libxml has a
'recover' mode that will correct what it can and process the entire
document -- even if it is not well-formed. It works surprisingly well.

Another option is writing your own recursive descent parser. See
http://snippets.dzone.com/posts... for a starting point.

-- Mark.

Free Lunch

2/20/2012 11:30:00 PM

0

On Sun, 19 Feb 2012 23:49:43 -0800, Jason@nospam.com (Jason) wrote in
alt.talk.creationism:

>In article
><52eb3329-e66f-4985-9d12-5b706c08fb5e@x19g2000yqh.googlegroups.com>,
>Devils Advocaat <mankygoat7@gmail.com> wrote:
>
>> On Feb 19, 7:48=A0pm, Ja...@nospam.com (Jason) wrote:
>> > In article <7lv1k7duip0otmqhbsbctvu1eps2mcv...@4ax.com>, Free Lunch
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > <lu...@nofreelunch.us> wrote:
>> > > On Sat, 18 Feb 2012 23:49:55 -0800, Ja...@nospam.com (Jason) wrote in
>> > > alt.talk.creationism:
>> >
>> > > >In article <a4hvj7tfgrlfp8a5ubp3fduujm01djs...@4ax.com>, Free Lunch
>> > > ><lu...@nofreelunch.us> wrote:
>> >
>> > > >> On Sat, 18 Feb 2012 02:55:02 -0800, Ja...@nospam.com (Jason) wrote i=
>> n
>> > > >> alt.talk.creationism:
>> >
>> > > >> >In article
>> > > >> ><d500ac7d-fb6a-432b-9f7c-82e80eac9...@do4g2000vbb.googlegroups.com>=
>> ,
>> > > >> >Devils Advocaat <mankygo...@gmail.com> wrote:
>> >
>> > > >> ...
>> >
>> > > >> >> But you have insisted constantly that abortion is first degree mu=
>> rder.
>> >
>> > > >> >> So how can you say its okay to commit murder?
>> >
>> > > >> >> You contradict yourself so often it is unbelievable.
>> >
>> > > >> >Nothing is simple--there are always some exceptions to most things.
>> >
>> > > >> Do you understand that you are arguing for the laws we have today?
>> >
>> > > >That's not true. Nearly 50 million unborn babies have been killed sinc=
>> e
>> > > >Roe vs. Wade was handed down 37 years ago. In most of those cases, the
>> > > >mother's lives were never in any danger.
>> >
>> > > I was under the impression that you had said that almost all abortions
>> > > should take place during the first trimester and that later abortions
>> > > should take place only because of the risk they pose to the mother. The
>> > > current law is not much different from that.
>> >
>> > Good point. That is correct. I hope that as a result of the morning after
>> > pill--that most abortion clinics will close down due to the lack of
>> > business.
>>
>> Unlikely.
>>
>> However there is a simple solution.
>>
>> The anti-abortionists need only, each one individually, lobby their
>> congressman (or woman) to remove abortion-on-demand from the abortion
>> legislation.
>>
>> Simple, isn't it?
>>
>> Or is it too much hassle?
>
>My congressmen (mostly all liberals) don't listen to me.
>
They would be fools to listen to your ideas. Since they are not
reactionary Republicans, they probably are not fools.

Jason

2/21/2012 5:36:00 AM

0

In article <2rl5k71siu7mj0i01aogtqgbmt4f9d75e5@4ax.com>, Free Lunch
<lunch@nofreelunch.us> wrote:

> On Sun, 19 Feb 2012 23:49:43 -0800, Jason@nospam.com (Jason) wrote in
> alt.talk.creationism:
>
> >In article
> ><52eb3329-e66f-4985-9d12-5b706c08fb5e@x19g2000yqh.googlegroups.com>,
> >Devils Advocaat <mankygoat7@gmail.com> wrote:
> >
> >> On Feb 19, 7:48=A0pm, Ja...@nospam.com (Jason) wrote:
> >> > In article <7lv1k7duip0otmqhbsbctvu1eps2mcv...@4ax.com>, Free Lunch
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > <lu...@nofreelunch.us> wrote:
> >> > > On Sat, 18 Feb 2012 23:49:55 -0800, Ja...@nospam.com (Jason) wrote in
> >> > > alt.talk.creationism:
> >> >
> >> > > >In article <a4hvj7tfgrlfp8a5ubp3fduujm01djs...@4ax.com>, Free Lunch
> >> > > ><lu...@nofreelunch.us> wrote:
> >> >
> >> > > >> On Sat, 18 Feb 2012 02:55:02 -0800, Ja...@nospam.com (Jason)
wrote i=
> >> n
> >> > > >> alt.talk.creationism:
> >> >
> >> > > >> >In article
> >> > > >>
><d500ac7d-fb6a-432b-9f7c-82e80eac9...@do4g2000vbb.googlegroups.com>=
> >> ,
> >> > > >> >Devils Advocaat <mankygo...@gmail.com> wrote:
> >> >
> >> > > >> ...
> >> >
> >> > > >> >> But you have insisted constantly that abortion is first
degree mu=
> >> rder.
> >> >
> >> > > >> >> So how can you say its okay to commit murder?
> >> >
> >> > > >> >> You contradict yourself so often it is unbelievable.
> >> >
> >> > > >> >Nothing is simple--there are always some exceptions to most things.
> >> >
> >> > > >> Do you understand that you are arguing for the laws we have today?
> >> >
> >> > > >That's not true. Nearly 50 million unborn babies have been
killed sinc=
> >> e
> >> > > >Roe vs. Wade was handed down 37 years ago. In most of those cases, the
> >> > > >mother's lives were never in any danger.
> >> >
> >> > > I was under the impression that you had said that almost all abortions
> >> > > should take place during the first trimester and that later abortions
> >> > > should take place only because of the risk they pose to the mother. The
> >> > > current law is not much different from that.
> >> >
> >> > Good point. That is correct. I hope that as a result of the morning after
> >> > pill--that most abortion clinics will close down due to the lack of
> >> > business.
> >>
> >> Unlikely.
> >>
> >> However there is a simple solution.
> >>
> >> The anti-abortionists need only, each one individually, lobby their
> >> congressman (or woman) to remove abortion-on-demand from the abortion
> >> legislation.
> >>
> >> Simple, isn't it?
> >>
> >> Or is it too much hassle?
> >
> >My congressmen (mostly all liberals) don't listen to me.
> >
> They would be fools to listen to your ideas. Since they are not
> reactionary Republicans, they probably are not fools.

The real reason they don't listen to me is because I don't give them $100,000.


Jason

2/21/2012 5:43:00 AM

0

In article <jpl5k7tq210brf9ocqj1f7cdia86nfrnri@4ax.com>, Free Lunch
<lunch@nofreelunch.us> wrote:

> On Sun, 19 Feb 2012 23:51:21 -0800, Jason@nospam.com (Jason) wrote in
> alt.talk.creationism:
>
> >In article <sok2k71n25g6j5d7lo6nmu261ig05v1q40@4ax.com>, Free Lunch
> ><lunch@nofreelunch.us> wrote:
> >
> >> On Sun, 19 Feb 2012 11:48:04 -0800, Jason@nospam.com (Jason) wrote in
> >> alt.talk.creationism:
> >>
> >> >In article <7lv1k7duip0otmqhbsbctvu1eps2mcvvae@4ax.com>, Free Lunch
> >> ><lunch@nofreelunch.us> wrote:
> >> >
> >> >> On Sat, 18 Feb 2012 23:49:55 -0800, Jason@nospam.com (Jason) wrote in
> >> >> alt.talk.creationism:
> >> >>
> >> >> >In article <a4hvj7tfgrlfp8a5ubp3fduujm01djsrpf@4ax.com>, Free Lunch
> >> >> ><lunch@nofreelunch.us> wrote:
> >> >> >
> >> >> >> On Sat, 18 Feb 2012 02:55:02 -0800, Jason@nospam.com (Jason) wrote in
> >> >> >> alt.talk.creationism:
> >> >> >>
> >> >> >> >In article
> >> >> >> ><d500ac7d-fb6a-432b-9f7c-82e80eac93ea@do4g2000vbb.googlegroups.com>,
> >> >> >> >Devils Advocaat <mankygoat7@gmail.com> wrote:
> >> >> >>
> >> >> >> ...
> >> >> >>
> >> >> >> >> But you have insisted constantly that abortion is first degree
> >murder.
> >> >> >> >>
> >> >> >> >> So how can you say its okay to commit murder?
> >> >> >> >>
> >> >> >> >> You contradict yourself so often it is unbelievable.
> >> >> >> >
> >> >> >> >Nothing is simple--there are always some exceptions to most things.
> >> >> >>
> >> >> >> Do you understand that you are arguing for the laws we have today?
> >> >> >
> >> >> >That's not true. Nearly 50 million unborn babies have been killed since
> >> >> >Roe vs. Wade was handed down 37 years ago. In most of those cases, the
> >> >> >mother's lives were never in any danger.
> >> >> >
> >> >> I was under the impression that you had said that almost all abortions
> >> >> should take place during the first trimester and that later abortions
> >> >> should take place only because of the risk they pose to the mother. The
> >> >> current law is not much different from that.
> >> >
> >> >Good point. That is correct. I hope that as a result of the morning after
> >> >pill--that most abortion clinics will close down due to the lack of
> >> >business.
> >> >
> >> You forget that a large share of the anti-abortion movement, the
> >> anti-choice movement, want to ban the morning after pill and all other
> >> forms of birth control. Even Rick Santorum complains about it being
> >> legal.
> >
> >Some of them agree with me since it will mean that it will cause some
> >abortion clinics to close down and that is a good thing.
> >
> Why is that a good thing?
>
> Why should women be forced to bring unwanted fetuses to term? Is it
> because the racists cannot find enough white babies to adopt?

You may want to visit this website:

www.40daysforlife.com

That Christian ministry has been able to close down 16 abortion clinics in
four years. They have also caused 53 abortion industry employees to leave
their jobs.