Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make a code go on

Status
Not open for further replies.

presfox

Technical User
Joined
Jan 30, 2004
Messages
15
Location
NL
Im using a quite complicated script for parsing XML

so ill try to explain:

Im parsing from an XML file
As you can see there there are a number of fields. But my script now only parses the first one, as i need to parse them all, The problem here is in the ID, i can make him check or there is an ID change, and if there is 1 it goes to the next line, but the id is not changed them but added so:

first attack id: 1
second attack id added to the db: 1 2
third one : 1 2 3
fourth one: 1 2 3 4

as over 8000 lines are added to the real XML file im gonna use, it is kind off flooding my DB

any suggestions?
 
loop of some kind sounds right

Bastien

Any one have a techie job in Toronto, I need to work...being laid off sucks!
 
DRJ478:
I don't know that PHP's builtin XML functions are necessarily the correct way to handle XML. They are certainly the handiest way to deal with XML that has an unknown structure.

presfox:
If you do decide to use PHP's expat XML-parsing functions, I recommend that you remove from the XML all whitespace that appears outside of XML tags. You'll get a cleaner parse.

All:
<off-topic aside>
One of these days, someone is going to make me understand the world's fascination with XML. I see more people misuse it.

If the structure of the data is fixed, there's no real reason to even use XML. XML is only worth the data overhead if the structure of the data is unknown.

Take presfox's sample data. By my count, there are 384 bytes of actual data in the sample.

Formatted as XML as shown (assuming the removal of all whitespace outside of the XML tags), you have to transmit 2644 bytes, an overhead of ~589%. For every byte of data, you have to transmit more than 5 bytes of metadata.

Even if you use single-character XML tags and remove the XML comment at the beginning of the file (again, assuming the removal of all whitespace outside the XML tags), you still have to transmit 1176 bytes, for an overhead of ~206%. For every byte of data, you have to transmit 2 bytes of metadata.

Format that as a tab-delimited ASCII file with <cr><lf> at the end of each record, and you've increased the amount of information to transmit to 488 bytes, an overhead of ~27%. For every 5 bytes of data, you have to transmit 1 character of formatting.

It seems to me that if you already know the structure of the data, it's pretty hard to justify the bandwidth and processing necessary to bandy all that extra data around.
</off-topic aside>

Want the best answers? Ask the best questions: TANSTAAFL!!
 
sleipnir214
Let me reissue my statement:
Have a look at the most specific way of handling XML data....
Better, yes?
I believe XML is good where it belongs, so your point is well made. The point of XML is universality and portability of information, not efficiency. If there's no need to port the data to a variety of platforms the efficiency should prevail. I agree with that.
 
DRJ478:
<facetious>
Better. Not perfect, but better....
</facetious>

XML isn't necessary for portability. Use of ASCII strings avoids the whole &quot;-endian&quot; issue and other portability issues.

The only place XML is even remotely necessary is when you're handed a piece of data that has a flexible structure -- one example is a telephone directory where a user may have more than one phone number. Since any user can have any number of phone numbers, XML can encapsulate the data in a way that allows for programmatic interpretation of the information.

But if the phone directory has one entry per user, it's less bandwidth and an easier parse to not use XML. I know I'd rather deal with explode() and a loop than deal with expat's parse arrays if the structure is static.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top