{"id":3430,"date":"2023-11-30T20:34:16","date_gmt":"2023-12-01T05:34:16","guid":{"rendered":"https:\/\/crm270s.wordpress.com\/?p=3430"},"modified":"2023-11-30T20:34:16","modified_gmt":"2023-12-01T05:34:16","slug":"extraction","status":"publish","type":"post","link":"https:\/\/crm270s.mycpamytax.com\/?p=3430","title":{"rendered":"extraction, xml export"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>use strict;<br>use warnings;<br>use XML::LibXML;<br>use Text::CSV;<br><br># Replace 'your_xml_file.xml' with the path to your XML file<br>my $xml_file = 'title.xml';<br><br># Create an XML::LibXML parser<br>my $parser = XML::LibXML-&gt;new;<br><br># Parse the XML file<br>my $doc = $parser-&gt;parse_file($xml_file);<br><br># Find all &lt;title&gt; tags in the XML<br>my @titles = $doc-&gt;findnodes('\/\/title');<br><br># Create a Text::CSV object to write to a CSV file<br>my $csv = Text::CSV-&gt;new({ binary =&gt; 1, eol =&gt; \"\\n\" });<br><br># Open the CSV file for writing<br>open my $csv_fh, '&gt;', 'oriental_medicine_seoul.csv' or die \"Failed to open CSV file: $!\";<br><br># Write header row to the CSV file<br>$csv-&gt;print($csv_fh, &#091;\"Title\"]);<br><br># Extract and write the text within each &lt;title&gt; tag to the CSV file<br>foreach my $title (@titles) {<br>    my $title_text = $title-&gt;to_literal;<br>    $csv-&gt;print($csv_fh, &#091;$title_text]);<br>}<br><br># Close the CSV file<br>close $csv_fh;<br><br># If no &lt;title&gt; tags are found<br>if (!@titles) {<br>    print \"No title tags found in the XML.\\n\";<br>} else {<br>    print \"Extraction complete. Titles saved to 'oriental_medicine_seoul.csv'.\\n\";<br>}<br><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[26],"tags":[],"class_list":["post-3430","post","type-post","status-publish","format-standard","hentry","category-codes"],"_links":{"self":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/posts\/3430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3430"}],"version-history":[{"count":0,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/posts\/3430\/revisions"}],"wp:attachment":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}