I am parsing XML and need a script that will read my XML file and add in the open tag for all missing open tags. Example from XML below: <promo_code/> has no matching open tag <promo_code> I need the code to scan and add missing open tags. End result would be <promo_code> <promo_code/> Example XML code below…

<orders> <order> <alt_number>2222</alt_number> <state>processed</state> <user_id>1234</user_id> <dd_id>54321</dd_id> <placed_at/> <total_price>449.0</total_price> <total_shipping_costs>90.0</total_shipping_costs> <discount>0</discount> <dd_status_code>HD</dd_status_code> <dd_status_desc>ORDER IS ON HOLD UNTIL 11/01/13</dd_status_desc> <promo_code/> <billing_address> <address_id/> <dd_customer_id/> <address_1>1212 Not Real</address_1> <address_2></address_2> <city>san mateo</city> <title></title> <company></company> <first_name>Jane</first_name> <last_name>Doe</last_name> <state_abbr/> <formated_telephone/> <zipcode/> <email>smith@smith.com</email> <country_code>USA</country_code> </billing_address> <transaction> </transaction> <shipments> <shipment_id>21286</shipment_id> <shipment> <shipping_address> <address_id>27696</address_id> <dd_customer_id/> <address_1>1212 Not Real</address_1> <address_2></address_2> <city>san jose</city> <title>Dr</title> <company></company> <first_name>Jane</first_name> <last_name>Doe</last_name> <state_abbr>CA</state_abbr> <formated_telephone>555-555-5555 Jane Smith</formated_teleph +one> <zipcode>95125-3344</zipcode> <email></email> <country_code>USA</country_code> </shipping_address> <delivery_date>2011-10-01</delivery_date> <gift>true</gift> <gift_email>smith@smith.com</gift_email> <gift_message>Happy Birthday</gift_message> <status>N</status> <tracking_nr></tracking_nr> <sent_at/> </shipment> </shipments> <line_items> <line_item> <line_item_id>16821</line_item_id> <dd_id>IDID</dd_id> <name>Keep It Coming</name> <quantity>1</quantity> <price>359.0</price> <shipment_id>21286</shipment_id> <shipping_costs>90.0</shipping_costs> <tax_amount>0</tax_amount> </line_item> </line_items> </order> <orders>

In reply to How can I add missing XML open tags by TheVend

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.