Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hello, and thank you all for the many prompt replies! :)

Roboticus- "Perhaps you have either (a) some wonky data, or (b) a bit of code you've not shown us is frobnicating it somewhere."

Yes! Perhaps both! I have a PHP function that generates XML data from a Woocommerce(Wordpress) database. I validated the output using several online XML validation tools and they all reported valid XML output. Thus I assumed that the PHP function was working properly.

hdb- "Have you tried to just use the output of the toHash function directly? With so much back and forth between hash and string, it is no wonder that Perl loses a few characters..."

No not yet, but thanks for the suggestion!

"While the usage of XML::Simple is discouraged even by its author, it should do exactly what you want here."

I initially wrote it using XML::Simple but upon discovering that it wasn't recommended anymore I decided to look for a more robust alternative.

"I am a bit confused by your logic here....Then you use Dumper again to print it."

Sometimes my logic can be a little fuzzy but no worries - it's as clear as mud.... And Using Dumper to print again was just for debugging. There are actually container variables storing hash values but they weren't relevant to the problem so I didn't include them.

Haukex - "Data::Dumper wouldn't just lose characters like that...."

I agree. I believe that the problem most likely exists between the keyboard and the chair (yours truly!) and not the module itself.

Anonymous- "valid XML data - show it please"

Yes, I should have posted the XML in the OP. Since it was validating elsewhere and was long and ugly I didn't bother. I've posted it below. The only changes are to some PII - IP address, domain name and email address. I also posted the output, below the XML.

Thanks again!

my($xml)='<?xml version="1.0"?> <root><order><id>359</id><order_number>359</order_number><created_at>2 +019-03-28 10:33:06</created_at><updated_at>2019-03-28 10:33:06</updat +ed_at><completed_at/><status>pending</status><currency>CAD</currency> +<total>12.00</total><subtotal>12.00</subtotal><total_line_items_quant +ity>3</total_line_items_quantity><total_tax>0.00</total_tax><total_sh +ipping>0.00</total_shipping><cart_tax>0.00</cart_tax><shipping_tax>0. +00</shipping_tax><total_discount>0.00</total_discount><shipping_metho +ds>Pickup</shipping_methods><order_key>wc_order_n13C7qFcbVcbI</order_ +key><payment_details><method_id>cop</method_id><method_title>Pay at P +ickup</method_title><paid_at/></payment_details><billing_address><fir +st_name>Joe</first_name><last_name>Blow</last_name><company_name/><ad +dress_1>123 Somestreet</address_1><address_2/><city>Moncton</city><pr +ovince_code>NB</province_code><province>New Brunswick</province><post +al_code>E4E 4E4</postal_code><country_code>CA</country_code><country> +Canada</country><email>someone@somewhere.com</email><phone>5065551212 +</phone></billing_address><shipping_address><first_name>Joe</first_na +me><last_name>Blow</last_name><company_name/><address_1>123 Somestree +t</address_1><address_2/><city>Moncton</city><province_code>NB</provi +nce_code><province>New Brunswick</province><postal_code>E4E 4E4</post +al_code><country_code>CA</country_code><country>Canada</country></shi +pping_address><note/><customer_ip>127.0.0.1</customer_ip><customer_us +er_agent>Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 +(KHTML, like Gecko) Chrome/127.0.0.1 Safari/537.36</customer_user_age +nt><customer_id>1</customer_id><view_order_url>https://www.mysite.com +/my-account/view-order/359/</view_order_url><line_items><id>307</id>< +subtotal>10.00</subtotal><subtotal_tax>0.00</subtotal_tax><total>10.0 +0</total><total_tax>0.00</total_tax><price>10.00</price><quantity>1</ +quantity><tax_class/><name>Pepperoni Pizza</name><product_id>15</prod +uct_id><variation_id>0</variation_id><product_url>https://www.mysite. +com/product/pepperoni-pizza/</product_url><product_thumbnail_url>http +s://www.mysite.com/wp-content/uploads/2019/03/pepperoni-pizza-150x150 +.jpg</product_thumbnail_url><sku/><meta/><id>308</id><subtotal>2.00</ +subtotal><subtotal_tax>0.00</subtotal_tax><total>2.00</total><total_t +ax>0.00</total_tax><price>1.00</price><quantity>2</quantity><tax_clas +s/><name>Pepsi</name><product_id>222</product_id><variation_id>0</var +iation_id><product_url>https://www.mysite.com/product/pepsi/</product +_url><product_thumbnail_url>https://www.mysite.com/wp-content/uploads +/2019/03/pepsi-can-150x150.jpg</product_thumbnail_url><sku/><meta/></ +line_items><shipping_lines><id>309</id><method_id>local_pickup</metho +d_id><method_title>Pickup</method_title><total>0.00</total></shipping +_lines><tax_lines/><fee_lines/><coupon_lines/></order></root>';
{ 'root' => { 'order' => { 'order_number' => '359', 'created_at' => '2019-03-28 10:33:06', 'total' => '12.00', 'total_shipping' => '0.00', 'tax_line' => '', 'total_discount' => '0.00', 'shipping_lines' => { 'total' => '0.00', 'method_title' => 'Pi +ckup', 'id' => '309', 'method_id' => 'local +_pickup' }, 'billing_address' => { 'email' => 'someone@ +somewhere.com', 'province_code' => ' +NB', 'city' => 'Moncton', 'address_' => '', 'postal_code' => 'E4 +E 4E4', 'country' => 'Canada +', 'address_1' => '123 +Somestreet', 'company_nam' => '', 'country_code' => 'C +A', 'last_name' => 'Blow +', 'phone' => '50655512 +12', 'first_name' => 'Joe +', 'province' => 'New B +runswick' }, 'payment_details' => { 'paid_a' => '', 'method_id' => 'cop' +, 'method_title' => 'P +ay at Pickup' }, 'id' => '359', 'cart_tax' => '0.00', 'shipping_tax' => '0.00', 'order_key' => 'wc_order_n13C7qFcbVcbI', 'shipping_methods' => 'Pickup', 'coupon_line' => '', 'subtotal' => '12.00', 'line_items' => { 'product_url' => [ 'https +://www.mysite.com/product/pepperoni-pizza/', 'https +://www.mysite.com/product/pepsi/' ], 'name' => [ 'Pepperoni Pi +zza', 'Pepsi' ], 'tax_clas' => '', 'product_thumbnail_url' = +> [ + 'https://www.mysite.com/wp-content/uploads/2019/03/pepperoni-pizz +a-150x150.jpg', + 'https://www.mysite.com/wp-content/uploads/2019/03/pepsi-can-150x +150.jpg' + ], 'subtotal_tax' => [ '0.00 +', '0.00 +' ], 'subtotal' => [ '10.00', '2.00' ], 'total' => [ '10.00', '2.00' ], 'price' => [ '10.00', '1.00' ], 'id' => [ '307', '308' ], 'met' => '', 'variation_id' => '0', 'quantity' => [ '1', '2' ], 'total_tax' => [ '0.00', '0.00' ], 'product_id' => [ '15', '222' ], 'sk' => '' }, 'completed_a' => '', 'status' => 'pending', 'updated_at' => '2019-03-28 10:33:06', 'customer_ip' => '127.0.0.1', 'not' => '', 'customer_user_agent' => 'Mozilla/5.0 (Wind +ows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome +/127.0.0.1 Safari/537.36', 'shipping_address' => { 'company_nam' => '' +, 'postal_code' => 'E +4E 4E4', 'country' => 'Canad +a', 'address_1' => '123 + Somestreet', 'first_name' => 'Jo +e', 'province' => 'New +Brunswick', 'last_name' => 'Blo +w', 'country_code' => ' +CA', 'province_code' => +'NB', 'city' => 'Moncton' +, 'address_' => '' }, 'total_tax' => '0.00', 'fee_line' => '', 'total_line_items_quantity' => '3', 'customer_id' => '1', 'currency' => 'CAD', 'view_order_url' => 'https://www.mysite.com +/my-account/view-order/359/' } }, 'xml' => { 'version' => '1.0' } }

In reply to Re: XML to Hash Truncating Keys Problem by Wayne
in thread XML to Hash Truncating Keys Problem by Wayne

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2021-06-23 05:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (114 votes). Check out past polls.

    Notices?