XML Novice Question

Discussion in 'XML' started by The Gnome, Dec 7, 2006.

  1. The Gnome

    The Gnome Guest

    Hi I'm receiving an XML feed from one of our business partners that I
    need to import into a database. I'm using XMLSpy and it really is
    pretty straight forward, but I think the xml I'm receiving has unneeded
    extra tags, thus I'm getting extra unneeded tables created.

    Example:

    <Reports>
    <Report>
    <Report Num>1</Report Num>
    <Items>
    <Item>
    <Item Num>1</Item Num>
    </Item>
    <Item>
    <Item Num>2</Item Num>
    </Item>
    </Items>
    </Report>
    </Reports>

    Am I correct in thinking the "container" tags are superflous (i.e.
    "Reports", "Items")? I think this is more correct:

    <Report>
    <Report Num>1</Report Num>
    <Item>
    <Item Num>1</Item Num>
    <Item>
    <Item Num>2</Item Num>
    </Item>
    </Report>
    The Gnome, Dec 7, 2006
    #1
    1. Advertising

  2. The Gnome wrote:
    > Am I correct in thinking the "container" tags are superflous (i.e.
    > "Reports", "Items")?


    That's up to whoever defined the XML-based language you're processing.
    If the DTD/schema calls for them, you can't leave them out because
    they're part of the structure of the document. Unlike browsers, XML
    tools do not try to guess what you meant; it's up to you to say it properly.

    <Reports>, or something like it, is definitely needed if a single
    document may contain more than one report. An XML document *must* have a
    single top-level element, so there would have to be something to contain
    the multiple reports.

    <Items> may not be strictly necessary in this case... but it really
    doesn't do any harm, and it may make some kinds of processing either.

    BTW, your rewritten version is broken in any case; you forgot one of the
    </Item> tags. All XML elements *must* be explicitly closed.



    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Dec 7, 2006
    #2
    1. Advertising

  3. In article <>,
    "The Gnome" <> wrote:

    > Hi I'm receiving an XML feed from one of our business partners that I
    > need to import into a database. I'm using XMLSpy and it really is
    > pretty straight forward, but I think the xml I'm receiving has unneeded
    > extra tags, thus I'm getting extra unneeded tables created.
    >
    > Example:
    >
    > <Reports>
    > <Report>
    > <Report Num>1</Report Num>
    > <Items>
    > <Item>
    > <Item Num>1</Item Num>
    > </Item>
    > <Item>
    > <Item Num>2</Item Num>
    > </Item>
    > </Items>
    > </Report>
    > </Reports>
    >
    > Am I correct in thinking the "container" tags are superflous (i.e.
    > "Reports", "Items")? I think this is more correct:
    >
    > <Report>
    > <Report Num>1</Report Num>
    > <Item>
    > <Item Num>1</Item Num>
    > <Item>
    > <Item Num>2</Item Num>
    > </Item>
    > </Report>


    The <Reports> element is superfluous if a single XML document can
    contain only one <Report> element. Ditto for <Items>. And the <Item>
    elements would be also, unless it's likely that additional elements
    would appear in each beyond the (bad) <Item Num> you show.

    The above isn't legal anyway, since <Item Num> is not a valid element
    name (spaces aren't allowed). In addition, your second sample fails to
    close one of the <Item> tags -- which is allowed (despite being poor
    practice) in HTML but not XML.

    = Steve =
    --
    Steve W. Jackson
    Montgomery, Alabama
    Steve W. Jackson, Dec 7, 2006
    #3
  4. Steve W. Jackson wrote:
    > The above isn't legal anyway, since <Item Num> is not a valid element
    > name (spaces aren't allowed).


    Whups; hate to admit I missed that. Ditto for <Report Num>. If the
    example you've shown us is really what you're receiving, you need to
    have a talk with whoever is generating it and get it fixed.

    Consider variants such as ItemNum or Item_Num... or just Num, since you
    know from context whether it's within the scope of an Item or Report.
    Or, if apporpriate, consider expressing that value as an attribute:
    <Report Num="1"> ... </Report>




    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Dec 7, 2006
    #4
    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. ra

    VHDL novice question

    ra, Jul 13, 2004, in forum: VHDL
    Replies:
    6
    Views:
    2,834
    Allan Herriman
    Jul 13, 2004
  2. sean
    Replies:
    1
    Views:
    589
    Cowboy \(Gregory A. Beamer\)
    Oct 20, 2003
  3. sean
    Replies:
    0
    Views:
    305
  4. sean
    Replies:
    2
    Views:
    540
    Kevin Spencer
    Dec 2, 2003
  5. sean

    Forms question - Novice

    sean, Feb 2, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    319
    Steve C. Orr [MVP, MCSD]
    Feb 2, 2004
Loading...

Share This Page