Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Welcome to the Monastery
 
PerlMonks  

Re: Why XML not well formed?

by BaldPenguin (Friar)
on Jun 30, 2005 at 11:40 UTC ( [id://471367]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Why XML not well formed?

I would spend special attention on those resource links, as mirod mentioned, the & is a great way to get that error and very common in urls with params.

Don
WHITEPAGES.COM | INC

Edit by castaway: Closed small tag in signature

Replies are listed 'Best First'.
Re^2: Why XML not well formed?
by nan (Novice) on Jun 30, 2005 at 11:49 UTC

    Hi Don,

    Yes you are right, but how can I overcome this '&' problem? I've tried to put '\' before '&' but it's doesn't work.

    many thanks!

    Nan

      You could regex the &:
      $line =~ s/(&)/$1amp;/g;

      Don
      WHITEPAGES.COM | INC

      Edit by castaway: Closed small tag in signature

        That would potentially disastrous effects if the XML contained any entities.

        --
        <http://www.dave.org.uk>

        "The first rule of Perl club is you do not talk about Perl club."
        -- Chip Salzenberg

        I think the proper way to control this sort of operation -- and keep it from screwing up other entity references (like &egrave; and &lt;, etc) is something like this:
        s/&(?!\w+;)/&amp;/;
        This is just assuming that every valid entity reference that might exist in the original text is limited to alphanumerics and underscores between the initial ampersand and the final semi-colon, which is probably a safe-enough assumption.

        But keep a backup of the original. If the data still causes parse errors after this simple edit, they might be different problems you haven't fixed yet, or they might be problems created by this simple edit. Careful diagnosis would be needed in that case.

        Hi Don,

        Sorry I used $line =~ s/(&)/(& amp;)/g; would it be different with yours?

        Many thanks, Nan

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://471367]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.