Membership is FREE – with unlimited access to all features, tools, and discussions. Premium accounts get benefits like banner ads and newsletter exposure. ✅ Signature links are now free for all. 🚫 No AI-generated (LLM) posts allowed. Share your own thoughts and experience — accounts may be terminated for violations.

Parsing an XML file

Status
Not open for further replies.
If anyone is good with parsing XML files I need some help, the source file contains;

<![CDATA[
good data<br/>
good data too<br/>
not needed data
]]>

How do I read the first 2 lines into MySql but not the 3rd?

Many thanks

Admin

Do you know any java? That's what I'd probably use if I were to do that.

Would offer to give you a hand with it but I've been coding all day and need a break!

Sent from my GT-I9300 using Tapatalk 2
 
I might be able to help Admin, pm me.

Just finished a load of xml parsing on my latest project.
 
If using PHP it would be something like this. :)

PHP:
<?php

$xml_string = <<<XML
<?xml version="1.0"?>
<root>
   <item>
       <![CDATA[good data<br/>good data too<br/>not needed data]]>
   </item>
</root>
XML;

$xml = simplexml_load_string($xml_string);

foreach($xml->item as $item) {
   // The last parameter is the lines you want + 1 (so for 2 lines it's 3)
   $chunks = explode('<br/>', $item, 3);
   $good_data = array($chunks[0], $chunks[1]);
   print_r($good_data);
}

?>

Just put your $good_data into your database. :D

You can test the above here: http://writecodeonline.com/php/
 
The code I pmed over was php.
Cheers :)

If using PHP it would be something like this. :)

PHP:
<?php

$xml_string = <<<XML
<?xml version="1.0"?>
<root>
   <item>
       <![CDATA[good data<br/>good data too<br/>not needed data]]>
   </item>
</root>
XML;

$xml = simplexml_load_string($xml_string);

foreach($xml->item as $item) {
   // The last parameter is the lines you want + 1 (so for 2 lines it's 3)
   $chunks = explode('<br/>', $item, 3);
   $good_data = array($chunks[0], $chunks[1]);
   print_r($good_data);
}

?>

Just put your $good_data into your database. :D

You can test the above here: http://writecodeonline.com/php/
 
Status
Not open for further replies.

Rule #1: Be Respectful

Do not insult any other member. Be polite and do business. Thank you!

Members online

No members online now.

Premium Members

New Threads

Domain Forum Friends

Lastest Listings

Our Mods' Businesses

*the exceptional businesses of our esteemed moderators
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Siusaidh AcornBot:
    Siusaidh has left the room.
      Siusaidh AcornBot: Siusaidh has left the room.
      Top Bottom