Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Parsing XML file and keeping the formatting tags

by choroba (Archbishop)
on Mar 22, 2018 at 16:49 UTC ( #1211550=note: print w/replies, xml ) Need Help??

in reply to Parsing XML file and keeping the formatting tags

Your input is not a valid XML. The id=1 should be id="1". After fixing that, the following seems to work for the input you showed:
#!/usr/bin/perl use warnings; use strict; use XML::LibXML; my $dom = 'XML::LibXML'->load_xml(location => 'file.xml'); for my $child ( @{ $dom->find('/trans-unit/*[self::source | self::target]') } ) { ( my $contents = join '', $child->childNodes ) =~ s,\n, <lb/> ,g; print $contents, $child->nodeName eq 'source' ? ' || ' : "\n"; }
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Parsing XML file and keeping the formatting tags
by corfuitl (Sexton) on Mar 22, 2018 at 18:56 UTC

    Thank you so much

    I added the " and it works :)

    However, I would like to have a deeper understanding of the code as I am not familiar. I will check it and will get back if any questions will arrise.


      This is not a code problem, it is a problem with incorrect formatting of XML data.

      Like any structured data format, you must stick with the standard, and ensure it is correct. Perhaps some programs will work with bad XML/JSON etc data, but properly written applications and modules will not (and should not imho).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1211550]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2021-04-19 01:20 GMT
Find Nodes?
    Voting Booth?

    No recent polls found