Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Interpreting XML Occurrence Indicators (foo | bar | baz)+

    Hi all --

    I'm working with a third-party XML feed. Pared down, the DTD looks like this:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE xml_dtd_noob [
    <!ELEMENT DateTimeStamp (#PCDATA)>
    <!ELEMENT Tournament (MatchTime, MatchNumber, complete?, (Players |  Games | Score)+)>
    <!ELEMENT MatchTime (#PCDATA)>
    <!ELEMENT MatchNumber (#PCDATA)>
    <!ELEMENT Players (Player*)>
    <!ELEMENT Player (PlayerName)>
    <!ELEMENT PlayerName (#PCDATA)>
    <!ELEMENT Games (Game*)>
    <!ELEMENT Game (GameNumber, Score?)>
    <!ELEMENT GameNumber (#PCDATA)>
    <!ELEMENT xml_dtd_noob (DateTimeStamp, Tournament)>
    <!ELEMENT Tournaments (Tournament*)>
    <!ELEMENT Score (Points)>
    <!ELEMENT Points (#PCDATA)>
    <!ELEMENT complete (#PCDATA)>
    ]>
    Can someone explain how the (Players | Games | Score)+ indicator (line 4) is supposed to work?

    I first interpreted it to mean that any one (and only one) of the three elements (Players, Games, Score) could be a child of Tournament (and could have multiple instances). But the data provider will commonly feed both Players and Games elements within the same Tournament. (And, to be fair, I'm not sure the XML data matches the given DTDs. It's a more complex structure than what's presented here, but no guarantee the data provider hasn't made changes over time and not reflected them in the content models.)

    Anyway, I'm having a hard time wrapping my head around the mututal exclusivity here.

    Why not:

    Code:
    <!ELEMENT Tournament (MatchTime, MatchNumber, complete?, Players+, Games+, Score+)>
    (Or are they equivalent?)

    Thanks in advance for the help.

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,473
    Thanks
    13
    Thanked 361 Times in 357 Posts
    nope, they’re not equivalent. it’s the order of elements that differs.

    Code:
    <!ELEMENT Tournament (MatchTime, MatchNumber, complete?, (Players |  Games | Score)+)>
    translates to:
    - first exactly 1 MatchTime element
    - after that exactly 1 MatchNumber element
    - after that 0 or 1 complete element
    - after that 1 or more elements out of the group [Players, Games, Score]

    while
    Code:
    <!ELEMENT Tournament (MatchTime, MatchNumber, complete?, Players+, Games+, Score+)>
    translates to:
    - first exactly 1 MatchTime element
    - after that exactly 1 MatchNumber element
    - after that 0 or 1 complete element
    - after that 1 or more Players elements
    - after that 1 or more Games elements
    - after that 1 or more Score elements
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • Users who have thanked Dormilich for this post:

    DeeTeeDee (04-26-2012)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •