XML Development

Moderators: None (Apply to moderate this forum)
Number of threads: 252
Number of posts: 451

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Schema to represent large array of numbers Posted by allelopath on 14 Jun 2005 at 12:07 PM
I have some data that looks like this:

1 0.0000 0.0714 0.512 0.383
2 0.0000 0.1538 0.258 0.239
3 0.2500 0.0800 0.256 0.109
4 0.0000 0.1154 0.213 0.132
... ... ... ... ...
365 0.5000 0.0370 0.034 0.012

that I want to put in xml format.

The 'brute force' method would be:
<day>
<number> 1 </number>
<percent1> 0.0714 </percent1>
<percent2> 0.512 </percent2>
<percent3> 0.383 </percent3>
<percent4> 0.0 </percent4>
</day>
and so on for 365 days.

Another method would be to have one string per line
<dayString>4 0.0000 0.1154 0.213 0.132 </dayString>
and then in the code parse the line into numbers.

Each of these 2 methods has advantages/disadvantages.
Are there any other better ways?
Report
Re: Schema to represent large array of numbers Posted by infidel on 14 Jun 2005 at 4:04 PM
: I have some data that looks like this:
:
: 1 0.0000 0.0714 0.512 0.383
: 2 0.0000 0.1538 0.258 0.239
: 3 0.2500 0.0800 0.256 0.109
: 4 0.0000 0.1154 0.213 0.132
: ... ... ... ... ...
: 365 0.5000 0.0370 0.034 0.012
:
: that I want to put in xml format.
:
: The 'brute force' method would be:
: <day>
: <number> 1 </number>
: <percent1> 0.0714 </percent1>
: <percent2> 0.512 </percent2>
: <percent3> 0.383 </percent3>
: <percent4> 0.0 </percent4>
: </day>
: and so on for 365 days.
:
: Another method would be to have one string per line
: <dayString>4 0.0000 0.1154 0.213 0.132 </dayString>
: and then in the code parse the line into numbers.
:
: Each of these 2 methods has advantages/disadvantages.
: Are there any other better ways?

Your latter suggestion would make for a smaller file, but rather negates the purpose of using XML in the first place. If all the pertinent values are going to be a single string in your XML that needs to be parsed later, what's the point of using XML instead of the plain file?

I would do one of the following:

<data>
    <day>
        <percentage>0.0000</percentage>
        <percentage>0.0714</percentage>
        <percentage>0.512</percentage>
        <percentage>0.383</percentage>
    </day>
    ...
</data>


Or perhaps:

<data>
    <day pct1="0.0000" pct2="0.0714" pct3="0.512" pct4="0.383" />
    ...
</data>


As long as the days will always be in numerical order, I don't think you need to include the number in the data.


infidel

$ select * from users where clue > 0
no rows returned


Report
Re: Schema to represent large array of numbers Posted by allelopath on 14 Jun 2005 at 4:57 PM
:
: <data>
:     <day pct1="0.0000" pct2="0.0714" pct3="0.512" pct4="0.383" />
:     ...
: </data>
: 

I've never seen this before.
What is the schema code for that?
Report
Re: Schema to represent large array of numbers Posted by infidel on 16 Jun 2005 at 9:53 AM
: :
: : <data>
: :     <day pct1="0.0000" pct2="0.0714" pct3="0.512" pct4="0.383" />
: :     ...
: : </data>
: : 

: I've never seen this before.
: What is the schema code for that?

I don't know about schemas, this is just basic XML. Any element in XML can have any number of attributes, which are name/value pairs, but the names have to be unique within a single element.

Like an image tag in HTML:

<img src="foo.jpg">

The "src" attribute has a value of "foo.jpg".


infidel

$ select * from users where clue > 0
no rows returned





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.