Membership is FREE, giving all registered users unlimited access to every Acorn Domains feature, resource, and tool! Optional membership upgrades unlock exclusive benefits like profile signatures with links, banner placements, appearances in the weekly newsletter, and much more - customized to your membership level!

Parsing an XML file

Status
Not open for further replies.

Admin

Administrator
Staff member
Joined
Jun 14, 2004
Posts
11,076
Reaction score
962
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
 
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.

The Rule #1

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

Premium Members

New Threads

Domain Forum Friends

Our Mods' Businesses

*the exceptional businesses of our esteemed moderators
General chit-chat
Help Users
  • No one is chatting at the moment.
      There are no messages in the current room.
      Top Bottom