detect duplicate element in SAX

U

usgog

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?
 
J

Joe Kesselman

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top