🔒 Locked
XML Basics?
Advertisement
Original Post
Hi,
I''ve been wondering for a while what XML is, and how it applies to not only game programming, but also to programming in general. Is it a good thing to learn or is it something that should be skipped by? Thanks!
Regards,
Mike
I went to that site and learned the ins and outs of XML in less than 30 minutes. I took the quiz at the end and got a 95% on it too.
I use XML to aid my scripting. I have all my scripts do the commands, and all the data is stored up in XML files. This way I can make an explosion in XML, than I can use that explosion in several scripts. Whenever I want to load that explosion, all I got to do is use the command "LoadXMLData foo.xml 0" in my script. I have XML data blocks, which is the 0 you saw in the command. To use that XML file, you just pass 0 or whatever the number is, and the command will take it. For example: "StartGEffect XML 0" takes the first parameter, which says to use a XML data block, and then the 0 corresponds to the loaded XML file, foo.xml.
[edited by - frenchfry164 on July 10, 2003 4:00:39 PM]
I use XML to aid my scripting. I have all my scripts do the commands, and all the data is stored up in XML files. This way I can make an explosion in XML, than I can use that explosion in several scripts. Whenever I want to load that explosion, all I got to do is use the command "LoadXMLData foo.xml 0" in my script. I have XML data blocks, which is the 0 you saw in the command. To use that XML file, you just pass 0 or whatever the number is, and the command will take it. For example: "StartGEffect XML 0" takes the first parameter, which says to use a XML data block, and then the 0 corresponds to the loaded XML file, foo.xml.
[edited by - frenchfry164 on July 10, 2003 4:00:39 PM]
For fun, I decided to configure a particle system using XML. Here is the configuration file:
<?xml version="1.0" ?>
<ParticleSystem xmlns="http://confetti" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Configuration.xsd">
<Volume name="vol0" type="point" />
<Volume name="vol1" type="line" length="10." />
<Volume name="vol2" type="rectangle" width="50." height="50." />
<Volume name="vol3" type="circle" radius="10." />
<Volume name="vol4" type="sphere" radius="10." />
<Volume name="vol5" type="box" width="10." height="10." depth="10." />
<Volume name="vol6" type="cylinder" height="10." radius="10." />
<Volume name="vol7" type="cone" height="10." radius="10." />
<BouncePlaneList name="bounceplanes">
<BouncePlane x="0." y="1." z="0." d="0." dampening=".5" />
</BouncePlaneList>
<ClipPlaneList name="clipplanes">
<ClipPlane x="0." y="1." z="0." d="0." />
</ClipPlaneList>
<Appearance name="appearance" radiusDelta="0." radialVelocity="0.">
<ColorDelta g="0." r="0.." b="0." a="-.05" />
</Appearance>
<Appearance name="texturedappearance" radiusDelta="0." radialVelocity="0." texture="res/ember.tga">
<ColorDelta g="-.05" r="-.20" b="-.05" a="-.05" />
</Appearance>
<Appearance name="streakappearance" radiusDelta="0." radialVelocity="0." size="2.">
<ColorDelta g="0." r="0." b="0." a="-.05" />
</Appearance>
<Environment name="environment" airFriction="0.4"> <!--bounce="bounceplanes" clip="clipplanes" /> -->
<Gravity x="0." y="-9.8" z="0." />
<WindVelocity x="0." y="0." z="0." />
<Gustiness x="40." y="10." z="40." />
</Environment>
<Emitter name="e2" type="textured" volume="vol3" environment="environment" appearance="texturedappearance" count="10000" lifetime="20." spread="0.8" minSpeed="30." maxSpeed="100." color="ff4cc0f2" sorted="0" />
<!--
<Emitter name="e0" type="point" volume="vol0" environment="environment" appearance="appearance" count="10000" lifetime="20." spread="0.4" minSpeed="30." maxSpeed="100." sorted="0" />
<Emitter name="e1" type="streak" volume="vol0" environment="environment" appearance="streakappearance" count="10000" lifetime="20." spread="0.4" minSpeed="30." maxSpeed="100." />
<Emitter name="sphere" type="sphere" volume="vol2" environment="environment" appearance="appearance" count="1000" spread="0.4" minSpeed="30." maxSpeed="100." />
-->
</ParticleSystem>
Maybe it''s just me but for my config files and other ASCII data storage needs, I created my own markup language instead of using XML. It''s much simpler and it fit my needs.
It goes like this :
There''s only 3 constructs :
[SectionName][/SectionName]
Variable = Variable Content
Variable = { array of data }
It goes like this :
[MODEL]
MESH_NUMBER=5;
[MESH0]
LAYER_NUMBER=1;
COLOR_MODE=RGBA_UNIQUE;
[LAYER0]
NAME=tllblind.bmp;
MODE=Basic;
[/LAYER0]
VERTEX=
{
4.43155, 19.4485, -5.08845, ... 8.96465,
}
NORMAL=
{
0.962076, -0.242682, ... 0.377799,
}
TEXTURE_COORDINATES=
{
0.767578, 0.310547, ... 0, 0.480469,
}
INDEX=
{
0, 1, 2, 3, 4, ... 1070, 1073, 1071,
}
COLOR=
{
1, 1, 1, 1,
}
[/MESH0]
[MESH1]
LAYER_NUMBER=0;
COLOR_MODE=RGB;
VERTEX=
{
36.2908, 57.4409, ..., -44.3097,
}
NORMAL=
{
0.707107, -0.707107, ... 0,
}
INDEX=
{
0, 1, 2..., 31,
}
COLOR=
{
0.952941, .... 0.309804,
}
[/MESH1]
[/MODEL]
There''s only 3 constructs :
[SectionName][/SectionName]
Variable = Variable Content
Variable = { array of data }
Over the past couple days ive been working on an app to teach people the Japanese Kana (got the idea from a thread I was reading here
) and use xml to store the data. I also had to write my own XML parser
which has taken 95% of the dev time
(xml.cpp and xml.h though i''m still writing the save functions)
MasterDepot
<charset name="hiragana">
<subset name="a - o">
<char img="images/hira_a.tga" ans="a"/>
<char img="images/hira_i.tga" ans="i"/>
<char img="images/hira_u.tga" ans="u"/>
<char img="images/hira_e.tga" ans="e"/>
<char img="images/hira_o.tga" ans="o"/>
</subset>
<subset name="ka - ko">
<char img="images/hira_ka.tga" ans="ka"/>
<char img="images/hira_ki.tga" ans="ki"/>
<char img="images/hira_ku.tga" ans="ku"/>
<char img="images/hira_ke.tga" ans="ke"/>
<char img="images/hira_ko.tga" ans="ko"/>
</subset>
<subset name="sa - so">
<char img="images/hira_sa.tga" ans="sa"/>
<char img="images/hira_shi.tga" ans="shi"/>
<char img="images/hira_su.tga" ans="su"/>
<char img="images/hira_se.tga" ans="se"/>
<char img="images/hira_so.tga" ans="so"/>
</subset>
</charset>
MasterDepot
quote:
Original post by elis-cool
Over the past couple days ive been working on an app to teach people the Japanese Kana (got the idea from a thread I was reading here) and use xml to store the data. I also had to write my own XML parser
which has taken 95% of the dev time
(xml.cpp and xml.h though i''m still writing the save functions)
MasterDepot
nice! you plan on making it LGPL or something?
btw, there are another ( the only ''free'' lib as far as I can tell ) XML lib for C++ : Xerces C++ Parser - how ever I cant quite figure out if the apache license will let me use it for commercial progs...
/Please excuse my bad spelling - My native language is binary not english
|Visit me
\Take my advice - I don''''t use it...
Writing your own XML parser completely defeats the purpose of XML in the first place.
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
quote:
Original post by Anonymous Poster
XML is an ugly and bloated way to store data, but it''s a nice buzzword (''X'' is always sexy) promoted by countless companies so it became popular. Better learn it, if not for your own projects, for the future at least. You''ll bump into XML every once in a while.
That XML tutorial page had a nice "joke" in there:quote:
XML Joke
Question: When should I use XML?
Answer: When you need a buzzword in your resume.
I use xml because it''s pretty, it''s simple, any web browser will render it all pretty-like, and it''s well-suited for heirarchical data. The loading of config files should never be the bottleneck in a game, so why worry about performance? I''d rather have the convenience of having every setting be easily edited without using custom utilities.
quote:
Original post by Arild Fines
Writing your own XML parser completely defeats the purpose of XML in the first place.
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
Right, there is only one XML parser, and no one can ever write a better one. Also, every person who ever uses XML needs every single feature designed by the W3C. So, if I want to make a configuration file for a calculator app, which uses five tags and is 8 lines long, I need xerxes, an XML parser several orders of magnitude larger than my whole app.
Right.
quote:
Original post by Ishan
Right, there is only one XML parser, and no one can ever write a better one.
No, there are lots of XML parsers. One better than the other.
quote:
Also, every person who ever uses XML needs every single feature designed by the W3C. So, if I want to make a configuration file for a calculator app, which uses five tags and is 8 lines long, I need xerxes, an XML parser several orders of magnitude larger than my whole app.
Then why use/call it XML in the first place? If you don''t implement the whole spec in your parser, IT''S NOT XML. It is Just-Another-Proprietary-Format.
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
quote:
Original post by Arild Fines
Then why use/call it XML in the first place? If you don't implement the whole spec in your parser, IT'S NOT XML. It is Just-Another-Proprietary-Format.
So if IE doesn't support blink tags properly, then it's not a HTML parser? A spec is a definition of what a format is in its most complete form. People who write parsers are free to pick and choose what features they implement. The following:
<?xml version="1.0"?>
<!DOCTYPE greeting SYSTEM "hello.dtd">
<greeting>Hello, world!</greeting>
is a well-formed XML document. Anything that parses that is an XML parser. XML parser means something that parses XML, not something that conforms to some abstract, complete specification.
What you are saying is that a bread machine isn't a bread machine unless it can make every kind of bread imaginable. If my bread machine is only capable of making one particular recipie of white bread, it still makes bread.
It's like saying a manufacturer of a car can't say "this car consumes fuel" if it doesn't take gas AND diesel AND kerosene and so on. A parser that implements a subset of a spec is still a parser of said spec, and such an implementation may be the only way to achieve acceptible speeds under certain circumstances.
Standards-obsessed programmers are really wasteful people. The smart ones eventually realize that in the real world, it's about getting functionality X working bug-free by the deadline, not about whether you conform to the w3c's spec.
[edited by - Ishan on July 13, 2003 8:27:00 PM]
quote:
Original post by Ishanquote:
Original post by Arild Fines
Then why use/call it XML in the first place? If you don''t implement the whole spec in your parser, IT''S NOT XML. It is Just-Another-Proprietary-Format.
So if IE doesn''t support blink tags properly, then it''s not a HTML parser?
Blink never was in any HTML spec.
quote:
A spec is a definition of what a format is in its most complete form. People who write parsers are free to pick and choose what features they implement.
At the cost of interoperability with other XML tools. If you don''t have that, you have no need for XML in the first place. XML only has value as a standard - if you don''t follow that standard, you can just as well use some other format, more tailored to your needs.
Arild, I think his point was that you don''t need to be 100 standards complient to qualify as XML parser.
Next to no C++ compilers are 100% standards complient from what I''ve read. MSVC6 (still used by a large amount of programmers I''m sure) is missing several key issues which were addressed in .NET, but does this make MSVC6 "not of a compiler"?
Its about finding the right tool for the right task. I could tell you right now for a project I''m working I''d rather use Ishan''s parser the Xerces. Why would I use an all purpose 99 in 1 tool when I just need a screwdriver?
Next to no C++ compilers are 100% standards complient from what I''ve read. MSVC6 (still used by a large amount of programmers I''m sure) is missing several key issues which were addressed in .NET, but does this make MSVC6 "not of a compiler"?
Its about finding the right tool for the right task. I could tell you right now for a project I''m working I''d rather use Ishan''s parser the Xerces. Why would I use an all purpose 99 in 1 tool when I just need a screwdriver?
I agree mostly with Arild.
However, there is a case for writing your own xml parser: when you have a source (e.g. quicken.com''s stock ticker values) and you want to extract the raw data from the XML and don''t give a toot about the transformations and such that may apply.
I would call it a ripper or an extractor rather than a parser, though.
Alternatively, you could write an XSLT to rip the values for you and then use a parser suited to your own needs on the resultant format. This is probably the ''best'' solution if you really don''t want to use a real xml parser; so Arild is, in my opinion, correct.
However, there is a case for writing your own xml parser: when you have a source (e.g. quicken.com''s stock ticker values) and you want to extract the raw data from the XML and don''t give a toot about the transformations and such that may apply.
I would call it a ripper or an extractor rather than a parser, though.
Alternatively, you could write an XSLT to rip the values for you and then use a parser suited to your own needs on the resultant format. This is probably the ''best'' solution if you really don''t want to use a real xml parser; so Arild is, in my opinion, correct.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement