Enjoy unlimited access to all forum features for FREE! Optional upgrade available for extra perks.

Parsing an XML file

Status
Not open for further replies.

Admin

Administrator
Staff member
Joined
Jun 14, 2004
Posts
11,137
Reaction score
929
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
 
Not a clue with Java but thanks anyway... and I know the feeling!

Coffee time ..
 
I might be able to help Admin, pm me.

Just finished a load of xml parsing on my latest project.
 
Hi Admin,

PM sent with working code.

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/
 
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!

Featured Services

Sedo - it.com Premiums

IT.com

Premium Members

AucDom
UKBackorder
Be a Squirrel
Acorn Domains Merch
MariaBuy Marketplace

New Threads

Domain Forum Friends

Other domain-related communities we can recommend.

Our Mods' Businesses

Perfect
Service
Laskos
*the exceptional businesses of our esteemed moderators
Top Bottom