Hello Experts, I need help in extracting some information from xml file using perl.

1) test.xml file

How can I extract hostname1.xxx.com(hostname) and key and env and then put it in one file ( a text file ) using perl scripts

Contents of xml file:

<httpsRoute hostname="abchostname1.xxx.com" port="443" environment="QA +"> <key>6924</key> </httpsRoute> <httpsRoute hostname="hostname3.xxx.com" port="7416" environment="CAT" +> <key>9990068</key> </httpsRoute>

Contents of text file should be:

Route #1 details:

Host=abchostname1.xxx.com

Environment=QA

key=6924

Route #2 details:

Host=hostname3.xxx.com

Environment=CAT

key=9990068

2) I'll have certficate.xml. Using perl how can i extract DN( subjectDN), CN, env and key and put them in a file using PERL Content of xml file:
<certDet env="QA" subjectDN="/C=US/ST=NC/L=Raleigh/O=DotNet/OU=ETD +;D/CN=test1.xxxx.com"> <key>1234</key> </certDet> <certDet env="dev" subjectDN="/C=US/ST=NC/L=Charlotte/O=xxxxx/OU=W +AS/CN=dev1.xxx.com"> <key>27166</key> </certDet>
Contents of files should be:

Entry1:

DN="/C=US/ST=NC/L=Raleigh/O=DotNet/OU=ET&D/CN=test1.xxxx.com"

CN=test1.xxxx.com

env=QA

key=1234

Entry2:

DN="/C=US/ST=NC/L=Charlotte/O=xxxxx/OU=WAS/CN=dev1.xxx.com"

CN=dev1.xxx.com

env=QA

key=1234


In reply to extracting attribute values which might have multiple occurences from xml file by tinkuPerlMonk2

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.