Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Re: XML or home-grown format?

Thread Tools

Re: XML or home-grown format?

JS Bangs
Posts: n/a
I've added comp.text.xml to the cross-posting for this, since it's
probably more concerned with XML than anything else at this point. So far,
we've been discussing whether it's worth the trouble to move a custom file
format for the perl module Lingua:honology over to XML. I pointed out an
original example line like:

> >d +anterior -distributed voice

Which would have to become:

> >In XML, this might have to be as verbose as:
> >
> ><symbol label="d`">
> > <feature name="anterior" value="+" \>
> > <feature name="distributed" value="-" \>
> > <feature name="voice" \>
> ></symbol>

To which MegaZone suggested the shorter version:

> <symbol label="d" anterior="+" distributed="-" voice="+" />
> Something like that is just as valid in XML,

My response:

The example you gave is *well-formed* XML, which is different from *valid*
XML. The problem is that your example could never be valid XML, because
the attributes needed to define a given <symbol> cannot be known ahead of
time in the module. Rather, the list of feature names is given in a
separate <featureset></featureset> section.

True, one could make the featureset declaration into a DTD, but that would
require the users of my module to write their own DTD's, which is too much
work for them. I'd rather leave the validation of features against the
featureset to the application--which I'm also writing, so it's not much of
a problem.

I could go your way, but it would require all XML files parsed by my
module to run in standalone mode, and would prevent writing any DTD that
could validate all such files.

> Using XPath you can find the element based on one attribute and get
> the value of another - as in this:
> ---
> use strict;
> use warnings;
> use XML::LibXML 1.0053;
> my $xmlFile;
> my $parser = XML::LibXML->new();
> open (XMLCONF, "<./pcCurrencyTable.xml") ||
> die "Can't open table: $!";
> while (<XMLCONF>) {
> $xmlFile .= $_;
> }
> close (XMLCONF);
> my $dom = $parser->parse_string($xmlFile);
> $xpath = "//CurrencyTable/CurrencyShift[\@number='840']/\@name";
> print( ($dom->findnodes($xpath))[0]->textContent() . "\n");
> ----
> That prints "USD".

Something like this could provide an elegant way for the Lingua:honology
module to do checking that a given file doesn't contain errors (i.e. that
all attributes or feature names given for a <symbol> match some feature
declared in the <featureset> section. Once I've decided on my format, I'll
have to consider exactly how to do this.

Jesse S. Bangs Removed)

Jesus asked them, "Who do you say that I am?"

And they answered, "You are the eschatological manifestation of the ground
of our being, the kerygma in which we find the ultimate meaning of our
interpersonal relationship."

And Jesus said, "What?"
Reply With Quote
Posts: n/a
On Fri, 25 Jul 2003 14:16:04 -0700, JS Bangs <(E-Mail Removed)>

>> print( ($dom->findnodes($xpath))[0]->textContent() . "\n");
>> ----
>> That prints "USD".

Actually, that would print "USD

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
Reply With Quote
Posts: n/a
Bren <(E-Mail Removed)> shaped the electrons to say:
>Actually, that would print "USD

Yes. Point.

I actually changed my mind when doing my production code which I'd
written the test file as prep for and used the ->getAttribute() method
since I could first do -hasAttribute() in an if clause and else set it
to some default value, etc.

More than one way.

-MZ, CISSP #3762, RHCE #806199299900541
<URL:(E-Mail Removed)> Gweep, Discordian, Author, Engineer, me..
"A little nonsense now and then, is relished by the wisest men" 508-755-4098
<URL:> <URL:> Eris
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Print XML parsing to JspWriter (out) Class org.xml.sax.helpers.NewInstance can not access a member of class javax.xml.parsers.SAXParser with modifiers "protected" Per Magnus L?vold Java 0 11-15-2004 02:27 PM
embedding xml in xml as non-xml :) Mark Van Orman XML 5 09-15-2004 05:57 AM
What XML technologies to learn first for "XML Processing" and "XML Mapping"? Bomb Diggy Java 0 07-28-2004 07:26 AM
Help on including one XML document within another XML document using XML Schemas Tony Prichard XML 0 12-12-2003 03:18 PM