Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Perl Advice: Don't Generate XML By Hand!
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Off the Wall
View previous topic :: View next topic  
Author Message
wswartzendruber
Veteran
Veteran


Joined: 23 Mar 2004
Posts: 1246
Location: Idaho, USA

PostPosted: Tue Oct 05, 2010 11:42 pm    Post subject: Perl Advice: Don't Generate XML By Hand! Reply with quote

Why not? Escaping? Why should I bring in a library to construct a templated XML document?
Back to top
View user's profile Send private message
jonnevers
Veteran
Veteran


Joined: 02 Jan 2003
Posts: 1594
Location: Gentoo64 land

PostPosted: Wed Oct 06, 2010 12:10 am    Post subject: Reply with quote

anecdotal story. i was just starting to work on team who had previously been crafting their own C based XML reader/writer program. The XML was coming from and going to a third party who had a well defined XSD Schema. A schema that was perpetually changing. The program was *fraught* with errors. i mean lots of level 1 defects...elements in the wrong place, incorrect escaping, etc. the datafiles were up to 1 gig in size (input and output files).

i was tasked with building a replacement. a system architect recommended an approach that used a OOP language and a XML parsing library that could generate an object model from a given XSD.

the initial release had its issue as it was new tech for the company but after that the defect count literally fell to zero. and one dev maintained it part time instead of two working on the C version full time.

i <3 C, this isn't about anything being wrong with C in and of itself
Back to top
View user's profile Send private message
dmitchell
Veteran
Veteran


Joined: 17 May 2003
Posts: 1159
Location: Austin, Texas

PostPosted: Wed Oct 06, 2010 12:51 am    Post subject: Re: Perl Advice: Don't Generate XML By Hand! Reply with quote

wswartzendruber wrote:
Why not? Escaping? Why should I bring in a library to construct a templated XML document?

Because it's tedious and error prone, because you are not an expert, and because if something goes wrong then you don't have to take all the blame.
_________________
Your argument is invalid.
Back to top
View user's profile Send private message
cach0rr0
Moderator
Moderator


Joined: 13 Nov 2008
Posts: 4123
Location: Houston, Republic of Texas

PostPosted: Wed Oct 06, 2010 1:01 am    Post subject: Reply with quote

so uhh, while the topic is fresh on everyone's mind, anyone know of an xml library under perl that properly decodes html escapes?

Meaning, I have a file with a bunch of say, &agrave; &igrave; and so forth. Everything else gets processed/parsed/decoded no issue, but these remain in their encoded form.

Been using XML::DOM so, dunno
Back to top
View user's profile Send private message
wswartzendruber
Veteran
Veteran


Joined: 23 Mar 2004
Posts: 1246
Location: Idaho, USA

PostPosted: Wed Oct 06, 2010 1:08 am    Post subject: Reply with quote

cach0rr0 wrote:
so uhh, while the topic is fresh on everyone's mind, anyone know of an xml library under perl that properly decodes html escapes?

Meaning, I have a file with a bunch of say, &agrave; &igrave; and so forth. Everything else gets processed/parsed/decoded no issue, but these remain in their encoded form.

Been using XML::DOM so, dunno

Anything other than ',",&,<,> aren't part of the spec.
Back to top
View user's profile Send private message
notageek
Tux's lil' helper
Tux's lil' helper


Joined: 05 Jun 2008
Posts: 131
Location: India

PostPosted: Wed Oct 06, 2010 2:55 am    Post subject: Reply with quote

XML::Simple for everything.
RegEx for escapes.
_________________
"Defeat is a state of mind. No one is ever defeated, until defeat has been accepted as a reality." -- Bruce Lee
Back to top
View user's profile Send private message
cach0rr0
Moderator
Moderator


Joined: 13 Nov 2008
Posts: 4123
Location: Houston, Republic of Texas

PostPosted: Wed Oct 06, 2010 3:24 am    Post subject: Reply with quote

wswartzendruber wrote:

Anything other than ',",&,<,> aren't part of the spec.


dont know why it took me 10 seconds to figure out tonight, and infinity before, but

Code:

use HTML::Entities;
...
print REBODY "Pattern " . decode_entities($data->getValue) . "\n";


and of course have to >:utf8 the open file handle
Back to top
View user's profile Send private message
notageek
Tux's lil' helper
Tux's lil' helper


Joined: 05 Jun 2008
Posts: 131
Location: India

PostPosted: Wed Oct 06, 2010 3:32 am    Post subject: Reply with quote

Yeah whatever :roll:

XML sucks

HTML too
_________________
"Defeat is a state of mind. No one is ever defeated, until defeat has been accepted as a reality." -- Bruce Lee
Back to top
View user's profile Send private message
cach0rr0
Moderator
Moderator


Joined: 13 Nov 2008
Posts: 4123
Location: Houston, Republic of Texas

PostPosted: Wed Oct 06, 2010 3:35 am    Post subject: Reply with quote

notageek wrote:
Yeah whatever :roll:

XML sucks

HTML too


regex would have been annoying, was a non-starter. I could have done it that way, but too time consuming.
Back to top
View user's profile Send private message
notageek
Tux's lil' helper
Tux's lil' helper


Joined: 05 Jun 2008
Posts: 131
Location: India

PostPosted: Wed Oct 06, 2010 3:37 am    Post subject: Reply with quote

Was joking.

RegEx can give you headaches, if there are libraries then using them is a good advice.
_________________
"Defeat is a state of mind. No one is ever defeated, until defeat has been accepted as a reality." -- Bruce Lee
Back to top
View user's profile Send private message
cach0rr0
Moderator
Moderator


Joined: 13 Nov 2008
Posts: 4123
Location: Houston, Republic of Texas

PostPosted: Wed Oct 06, 2010 3:45 am    Post subject: Reply with quote

notageek wrote:
Was joking.

RegEx can give you headaches, if there are libraries then using them is a good advice.


regex is probably the only thing I'm at all completely 100% comfortable with. In perl, that is, non-pcre is just infuriating, and why every regex i end up half-assing in something like sed, i end up eventually getting frustrated and throwing together something in perl to do $task.
Back to top
View user's profile Send private message
notageek
Tux's lil' helper
Tux's lil' helper


Joined: 05 Jun 2008
Posts: 131
Location: India

PostPosted: Wed Oct 06, 2010 3:53 am    Post subject: Reply with quote

I have to occasionally write PHP too and everytime I do, I get into an infuriating rage. It only looks like perl superficially, but it is utterly clumsy.

For example:
Code:

$pttrn = '/(\w+)(\s+)(\w+)/';
$repl  = '$1_$3';
$name  = preg_replace($pttrn,$repl,$name);

_________________
"Defeat is a state of mind. No one is ever defeated, until defeat has been accepted as a reality." -- Bruce Lee
Back to top
View user's profile Send private message
cach0rr0
Moderator
Moderator


Joined: 13 Nov 2008
Posts: 4123
Location: Houston, Republic of Texas

PostPosted: Wed Oct 06, 2010 4:04 am    Post subject: Reply with quote

yikes. dunno php, but that's clunky as hell compared to:


Code:

$somestring =~ s/\s/_/g;
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Off the Wall All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum