Hi I'm trying to get some records of a xml file(s). The point of my code is to get all the node values printed out. As long as there arent multiple "twin" nodes its going good. I have the node <BaseItemDetails> that can appear multiple times on one record. Xml looks like this :
<Invoice> <InvoiceHeader> <InvoiceType></InvoiceType> <InvoiceStatus></InvoiceStatus> <InvoiceNumber></InvoiceNumber> <InvoiceDate></InvoiceDate> <Supplier> <Name> </Name> <OrgNumber></OrgNumber> <VatId></VatId> </Supplier> </InvoiceHeader> <InvoiceDetails> <BaseItemDetails> <Description></Description> <PerQuantity></PerQuantity> <QuantityInvoiced></QuantityInvoiced> <UnitOfMeasure></UnitOfMeasure> <LineItemGrossAmount></LineItemGrossAmount> <LineItemAmount></LineItemAmount> <SuppliersProductId></SuppliersProductId> <UnitPrice></UnitPrice> <StartDate></StartDate> <EndDate></EndDate> </BaseItemDetails> <BaseItemDetails> ------------------- -------------------- ----------------- </BaseItemDetails> </InvoiceDetails> </Invoice>
So far I have this code wich I want to change to make this work. :
foreach my $row ($xp->findnodes('Invoice')){ my $description= $row->find('InvoiceDetails/BaseItemDetails/Desc +ription')->string_value; ----------- ----------- print "$description "; }
How can i extract the <BaseItemDetails> for each record ? I Have no problem getting the data I need until I reach the multiple "simular" records. I can get the first "record" but clueless on how to get the next. Iv also managed to get all the <baseItemsDetails> printed out, but then i have no way of knowing wich record they belong to from the start. Wich is a big point. Whats the proper way to do this ? Do i need something different the xpath ? I`m pretty new to perl, so really any tips/advice is appriciated.

In reply to Problems with multiple records in xml file , Xpath by joppei

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.