Hello, I have a wired problem while parsing an XML file using LibXML. I googled it and unfortunately I could not find solution. Here is the code:
if (@files !=0){
foreach $file (@files) {
$parser = XML::LibXML->new();
$tree = $parser->parse_file($file);
$root = $tree->getDocumentElement;
@changes = $root->getElementsByTagName('change');
foreach $change (@changes) {
@classDetail = $change->getElementsByTagName('class');
if (@classDetail !=0){
$className=$classDetail[0]->getAttribute('name');
print "className= " .$className ."\n";
}
}
undef ($parser)
}
}
closedir(DIR);
For some files it works fine, but for some other files it gives the error "Couldn’t create file parser context for file "somename.xml": No such a file or directory at... ". For example, I rename a file (for which parsing was successful) and then I rerun my scripts on both files. For the original file it works ok but on the copied one I receive the above mentioned error. However, the content of the two files are exactly the same, and just their names are different.
Any idea?
Thanks,
Laleh
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.