Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Thank you for your reply.

I adapted my code according to your code and it works. However, I have another issue. It doesn't work with all XML files I have. the difference is that the one files has

<xliff version="1.1" xml:lang='en'>

and it works, while the other one has

<xliff xmlns:m="http://www.xxx.com/mxml/2.0" xmlns="urn:xx:names:tc:xml:document:1.2" version="1.2" m:version="2.3" m:level="1">

and it doesn't work.

Moreover, the second file has the structure below.

Here is my code

#!/usr/bin/perl use 5.010; use strict; use warnings; use XML::LibXML; my $new_values_file = shift; open my $in, '<', $new_values_file or die "$new_values_file: $!"; chomp(my @new_values = <$in>); my $dom = 'XML::LibXML'->load_xml(IO => *STDIN); my $i = 0; foreach my $alt_trans ($dom->findnodes('//file/body/group/unit/alt-tit +le/otherTitle[@origin="title"]')) { print $alt_trans->to_literal(); $alt_trans->removeChildNodes if $alt_trans->findnodes('text()'); $alt_trans->appendText($new_values[$i]); $i++; }

And one more question. Why in this file it doesn't work? Because there are blocks of <group> elements? Is my Xpath correct with this structure?

... <group> <unit id="3Ojs1SLwMmEHK8mJ0_dc2:43”> <titleEN>{3&gt;19&lt;3}</ titleEN > <titleFR>{3&gt;19&lt;3}</ titleFR > <alt-title origin="tilte"><otherTitle/></ alt-title> <alt-title origin="price"><otherPrice/></ alt-title> </unit> </group> <group> <unit id="3Ojs1SLwMmEHK8mJ0_dc2:43”> <titleEN>{3&gt;19&lt;3}</ titleEN > <titleFR>{3&gt;19&lt;3}</ titleFR > <alt-title origin="tilte"><otherTitle/></ alt-title> <alt-title origin="price"><otherPrice/></ alt-title> </unit> </group> ...

In reply to Re^4: Update nodes in XML document by corfuitl
in thread Update nodes in XML document by corfuitl

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-20 03:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found