falco has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: PERL/XML
by mirod (Canon) on Feb 19, 2001 at 23:45 UTC | |
A pointy bracket does not an XML document make! <!CDATA[ Test tittel ]> - <!CDATA[ test ingres ]> - <![CDATA[ http://www.test.com/test ]]>This is not XML. An XML document is something with a root element and nested elements, something like:
You might even want to add an XML declaration at the top of your file, just to make things more clear, and because I see you hitting encoding problems fairly soon in your experiments: <?xml version="1.0" encoding="ISO-8859-1"?>Then as OeufMayo mentionned you should use an XML parser, at least it parses real XML as opposed to what your code seems to do (I can't tell considering the formatting). Now after reading your code maybe your document is really an XML document, and I just got confused by the formatting, but in any case, you should still use a parser. If you don't you are not parsing XML but an undefined subset of XML. That will bite you one day. From what I can guess from your code you use <artikle> as a delimiter between articles. This prevents you from using attributes to the artikle element. You also seem to be wrapping all your text in CDATA. Why not. But then <url>, which you also use a a delimiter is a valid string in any element. Do yourself a favor and use XML::PYX or XML::Simple. You will be surprised at how easy they are to use and you will know that you have done things right, instead of writing a dirty hack that will crash baddly when you start using it in production code. | [reply] [d/l] [select] |
|
Re: PERL/XML
by aardvark (Pilgrim) on Feb 20, 2001 at 00:30 UTC | |
Matt Sergeant's AxKit: http:://www.axkit.org The Apache XML Project http://xml.apache.org If you are trying to ramp up quickly on XML here are a few good links Archives of the perl-xml mailing list http://mailarchive.activestate.com/browse/perl-xml XML.com ( has lots of good articles) http://www.xml.com The World Wide Web Consortium (which maintains the standard) http://www.oasis-open.org/cover/sgml-xml.html XMLHack http://www.xmlhack.com/ You also may want to check out David Cross's new book Data Munging with Perl. It has a good section on XML & HTML parsers. You can even get it as an e-book, which is so cool. http://www.manning.com/cross/index.html Anyway, I hope this helps. Good Luck. Get Strong Together!! | [reply] |
|
Re: PERL/XML
by falco (Initiate) on Feb 20, 2001 at 01:05 UTC | |
Hello - Below you'll find a Perl script and XML code. The .pl file reads from the .xml file, then turns the XML info into an HMTL document. The script works, but it works too well. I'm trying to extract the information from between the < ! [ CDATA ] > tags. But instead it retrieves everything (the < ! [ CDATA ] > and the info within it). How can I have the script pull just the info from within the brackets? XML:
PERL:
| [reply] [d/l] [select] |
by mirod (Canon) on Feb 20, 2001 at 02:11 UTC | |
I hope you are still having formatting problems: your XML is still not valid, <![CDATA and]]> must be written as-is, without spaces. Anyway, using XML::Simple here is how you get the information:
You should actually avoid unnecessary line returns within the XML documents, they _are_ significant:
Then you can get rid of the 2 lines that remove leading and trailing spaces. Note that I still can't figure out whether you real XML document includes only one article or several, in which case the format of the data as loaded by XML::Simple will change. As should your XML data actually (each article should be wrapped in a tag). Usually I use the following script to figure out what's going on and how XML::Simple digests my document:
So finally I think what you are looking for night be something like:
| [reply] [d/l] [select] |
by falco (Initiate) on Feb 20, 2001 at 10:02 UTC | |
| [reply] |
|
(redmist) Re: PERL/XML
by redmist (Deacon) on Feb 19, 2001 at 23:32 UTC | |
redmist Silicon Cowboy | [reply] [d/l] |