• Welcome to AcornDomains.co.uk, a friendly community for UK domain investors, developers and anyone interested in domain names.

    Whether you're looking to buy or sell domains, learn more about the UK domain market, get feedback on your names, or simply chat with other domainers, you're in the right place. AcornDomains has been bringing together people from across the UK domain industry for many years, from complete beginners to experienced investors.

    Have a look around, join the discussions and, if you haven't already, create a free account and introduce yourself.

Parsing an XML file

Status
Not open for further replies.

AdminAdmin is verified member.

Administrator
Acorn Staff
Acorn Moderator
Developer
Server Admin
Nominet Registrar
Joined
Jun 14, 2004
Posts
11,191
Reaction score
1,059
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.
Top Bottom