Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 7th, 2006, 04:45 PM
The Gnome
Guest
 
Posts: n/a
Default XML Novice Question

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>

  #2  
Old December 7th, 2006, 06:15 PM
Joseph Kesselman
Guest
 
Posts: n/a
Default Re: XML Novice Question

The Gnome wrote:
Quote:
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.

<Itemsmay 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
</Itemtags. All XML elements *must* be explicitly closed.



--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
  #3  
Old December 7th, 2006, 06:25 PM
Steve W. Jackson
Guest
 
Posts: n/a
Default Re: XML Novice Question

In article <1165511035.649815.158290@16g2000cwy.googlegroups. com>,
"The Gnome" <joe.cairns@gmail.comwrote:
Quote:
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 <Reportselement is superfluous if a single XML document can
contain only one <Reportelement. 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 Numyou show.

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

= Steve =
--
Steve W. Jackson
Montgomery, Alabama
  #4  
Old December 7th, 2006, 07:15 PM
Joseph Kesselman
Guest
 
Posts: n/a
Default Re: XML Novice Question

Steve W. Jackson wrote:
Quote:
The above isn't legal anyway, since <Item Numis 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
 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles