You are here:  » extracting data into fields from XML


extracting data into fields from XML

Submitted by baggagepin on Sun, 2013-05-12 20:12 in

Hi David,

I have an XML file (see below) which when I run through the parser only produces one field. I can't figure this out. If you have a moment can you please advise.

Many thanks,

Dereck

XML

<Aircraft>
<fch>20130512152537</fch>
<fn>UAL959</fn>
<far>N659UA</far>
<fat>B763</fat>
<coicao>UAL</coicao>
<forgiata>LHR</forgiata>
<fdstiata>ORD</fdstiata>
<criata>LHR-ORD</criata>
<tkoapt>EGLL</tkoapt>
</Aircraft>
<Aircraft>
<fch>20130512152541</fch>
<fn>ROT392</fn>
<far>YR-ASA</far>
<fat>A318</fat>
<coicao>ROT</coicao>
<forgiata>LHR</forgiata>
<fdstiata>OTP</fdstiata>
<criata>LHR-OTP</criata>
<tkoapt>EGLL</tkoapt>
<tkorwy>27R</tkorwy>
</Aircraft>
<Aircraft>
<fch>20130512152542</fch>
<fn>AFL2579</fn>
<far>VQ-BQY</far>
<fat>A333</fat>
<coicao>AFL</coicao>
<forgiata>LHR</forgiata>
<fdstiata>SVO</fdstiata>
<criata>LHR-SVO</criata>
<tkoapt>EGLL</tkoapt>
<tkorwy>27R</tkorwy>
</Aircraft>
<Aircraft>
<fch>20130512152543</fch>
<fn>BAW868</fn>
<far>G-EUYB</far>
<fat>A320</fat>
<coicao>BAW</coicao>
<forgiata>LHR</forgiata>
<fdstiata>BUD</fdstiata>
<criata>LHR-BUD</criata>
<tkoapt>EGLL</tkoapt>
<tkorwy>27L</tkorwy>
</Aircraft>

Submitted by support on Mon, 2013-05-13 09:49

Hi Derek,

It may be down to auto-detection if there are not many records in the document. Assuming that the document element (the containing tag above all <Aircraft> records is, for example <Results> use the Format String:

xml|RESULTS/AIRCRAFT/

...and that should be all it is...

If you're still not sure, if you could post a link to the full XML document (I'll remove before publishing your reply) and the section of your code making the call to MagicParser_parse() I'll check it out further for you...

Cheers,
David.

Submitted by baggagepin on Mon, 2013-05-13 18:28

Hi David,

many thanks for your reply.

I think I know whats causing the issue. At the top of the XML file I have:

<?xml version="2.0"?>
<AircraftList>
<Aircraft>

and so on.....

If I change the header to:

<?xml version="1.0" encoding="UTF-8"?>
<AircraftList>
<Aircraft>

It processes with any issues. The problem I have now id I have no control on how the XML file is constructed with regard to the header line. Would there be a reason why the XML file I get will ot process.

If you want to download the file here is the link, as you said please remove before you publish this reply.

{link saved}

Many thanks for your time.

Cheers,

Dereck

Submitted by support on Tue, 2013-05-14 12:43

Hi Derek,

That explains what is happening - your particular PHP installation is defaulting to iso-8859-1 encoding internally, and using this since the character encoding is not declared in your XML source.

I have followed up by email with a version of Magic Parser that forces the internal encoding to utf-8 for you which should do the trick...

All the best,
David
--
MagicParser.com

Submitted by support on Wed, 2013-05-15 13:52

Hi Derek,

My email to you seems to have bounced - I know you registered a long time ago so it may no longer be active, please could you email me from your current address and let me know your registration code and I'll forward the modifications...

Cheers,
David
--
MagicParser.com