Go Back   Velocity Reviews > Newsgroups > XML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

XML - detect duplicate element in SAX

 
Thread Tools Search this Thread
Old 09-24-2006, 10:23 PM   #1
Default detect duplicate element in SAX


The client will pass a xsd file to me through my API and it will be
parsed using SAX in JAVA. The XSD format is like following:
<xs:complexType name="Item">
<xs:all>
<xs:element name="item-id" type="xs:string" />
<xs:element name="item-name" type="xs:string" />
</xs:all>
</xs:complexType>

So there will be quite a few Items in the xsd. I want to make sure the
value of <item-id> is unique... So is there any algorithm that I can
use to detect that?



usgog@yahoo.com
  Reply With Quote
Old 09-24-2006, 10:30 PM   #2
Joe Kesselman
 
Posts: n/a
Default Re: detect duplicate element in SAX

wrote:
> So there will be quite a few Items in the xsd. I want to make sure the
> value of <item-id> is unique... So is there any algorithm that I can
> use to detect that?


If the name attribute isn't being validated against a schema or DTD
which says its value must be unique, you'll have to implement that in
your application code. Since you said you're working in Java, the
simplest approach would be to have your SAX handler maintain a Set
(hashset, treeset, or whatever version suits your data), checking for
whether a prior instance of that value has appeared; if not add it to
the set, but if so announce an error.


--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
  Reply With Quote
Old 09-25-2006, 02:09 AM   #3
Joe Kesselman
 
Posts: n/a
Default Re: detect duplicate element in SAX

Sorry; I misread that the first time around. (Didn't quite wake up today.)

To use schema to declare that the value of an Element must be unique, see

http://www.w3.org/TR/2004/REC-xmlsch...nt_Definitions
and the xs:unique directive.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump