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:

<article> <title>Test tittel</title> <ingres>test ingres</ingres> <url>http://www.test.com/test</url> </article>

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.


In reply to Re: PERL/XML by mirod
in thread PERL/XML by falco

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.