Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XML Novice Question

Reply
Thread Tools

XML Novice Question

 
 
The Gnome
Guest
Posts: n/a
 
      12-07-2006
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>

 
Reply With Quote
 
 
 
 
Joseph Kesselman
Guest
Posts: n/a
 
      12-07-2006
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
 
Reply With Quote
 
 
 
 
Steve W. Jackson
Guest
Posts: n/a
 
      12-07-2006
In article <(E-Mail Removed). com>,
"The Gnome" <(E-Mail Removed)> 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
 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      12-07-2006
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
 
Reply With Quote
 
 
 
Reply

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
VHDL novice question ra VHDL 6 07-13-2004 03:17 AM
Cisco ACL (Novice Question) Dominic Cisco 2 01-31-2004 06:17 AM
Server Error in '/' Application - when executing stored query - novice question sean ASP .Net 0 12-02-2003 05:43 AM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments