Hi,
I am beginner to perl programming language. I have large XML file it contains information about all diagnostic tests and their descriptions. each diagnostic test having one code like "1100" and regarding description in xml comments. for example my xml code like this
<data>
<testnumber>1100</testnumber>
<cause>battery short circuit</cause>
<description> check proper connection</description>
</data>
like as i shown in above i have more number of tests in my xml file. now i have to create hash table using perl script. in the hash table testnumber as a key and description as a value. finally i need to create hash table with all testnumbers and according descriptions.
ok - so you have a working script to parse the XML document correctly and now you want to build a hash of diagnostic codes? Please post the code you have done already.
Hi frank,
I am posting my code what i tried. i am reading a xml file and extracting information <DTC> to </DTC>. because my test number and test description starts and ends with that comments. i am posting my original code also here.
<DTC>
</DTC>
my perl script:
#!/usr/bin/perl
use warnings;
use strict;
open(File1, "formal.xml") or die "una
+ble to open file: $!\n";
open(File2, ">formal.xml") or die "unable to open file: $!\n";
while(<File1>)
{
chomp;
print "$_\n";
print File2 "$_\n";
}
close (File1);
close(File2);
while (<File>)
{
if (m|^\s*<DTC>| ... m|^\s*</DTC>|)
{
print;
}
}
but now i dnt know how to create hash table with this data.I have 100 testcodes and their descriptions like as same as above.
Hi,
After your suggetion i tried by using xml::simple, i have written like this
#!/usr/bin/perl
use warnings;
use strict;
use Data::Dumper;
number :1100 description: { <data>.......
</data>}.
number code :1200 description: { <data>.......
.............
</data>}.....
but i am able to printing
trouble code : 1100
i am not able to print description like above by using my code . what should i have to do in this case.
thanks in advance.
yes, i need to keep original xml data as same as it is . but my output must be testnumber and according description below like that.
---------- Post updated at 10:32 PM ---------- Previous update was at 10:29 PM ----------
yes
---------- Post updated 10-04-11 at 09:07 AM ---------- Previous update was 10-03-11 at 10:32 PM ----------
reply,
Thank you very much for your reply and i tried this one it prints the description line only but under description i need to print the xml original data as it is. like
testcode :1100
description: <data>
<testnumber>1100</testnumber>
<cause>battery short circuit</cause>
<description> check proper connection</description>
</data>
testcode :1200
description: <data>
<testnumber>1200</testnumber>
<cause>battery short circuit</cause>
<description> check proper connection</description>
</data>.............
like this. thanks in advance.
Post your sample input and expected output within code tags.
I am unable to understand your expected output because the text of your post runs into your output.
Click the hyperlink below to read the guidelines for adding code tags.
---------- Post updated at 07:15 PM ---------- Previous update was at 07:13 PM ----------
[quote=macmonster;302561528]
#!/usr/bin/perl
use warnings;
use strict;
use XML::Simple;
This assumes the xml file contains only one element. The output looks like this:
[code]
Hi, thank you very much for helping and my outpuy same like this but more number of tests. i need to print all tests and descriptions like same as above. i will try this one.