Re: XML or home-grown format?

Discussion in 'XML' started by JS Bangs, Jul 25, 2003.

  1. JS Bangs

    JS Bangs Guest

    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::phonology 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::phonology
    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
    http://students.washington.edu/jaspax/
    http://students.washington.edu/jaspax/blog

    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?"
     
    JS Bangs, Jul 25, 2003
    #1
    1. Advertising

  2. JS Bangs

    Bren Guest

    On Fri, 25 Jul 2003 14:16:04 -0700, JS Bangs <>
    wrote:

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


    Actually, that would print "USD
    "

    ;-)





    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 80,000 Newsgroups - 16 Different Servers! =-----
     
    Bren, Jul 25, 2003
    #2
    1. Advertising

  3. JS Bangs

    MegaZone Guest

    Bren <> 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:mailto:> Gweep, Discordian, Author, Engineer, me..
    "A little nonsense now and then, is relished by the wisest men" 508-755-4098
    <URL:http://www.megazone.org/> <URL:http://www.eyrie-productions.com/> Eris
     
    MegaZone, Jul 26, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. theRat
    Replies:
    2
    Views:
    418
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Jan 31, 2007
  2. default

    home grown strtok() function for review

    default, Sep 19, 2006, in forum: C Programming
    Replies:
    4
    Views:
    358
    default
    Sep 21, 2006
  3. joe
    Replies:
    2
    Views:
    379
    Kira Yamato
    Feb 14, 2008
  4. Nathaniel Talbott

    Home grown continuations

    Nathaniel Talbott, Aug 2, 2003, in forum: Ruby
    Replies:
    3
    Views:
    92
    Jim Weirich
    Aug 2, 2003
  5. JS Bangs

    XML or home-grown format?

    JS Bangs, Jul 24, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    123
    Julian Scarfe
    Jul 26, 2003
Loading...

Share This Page