![]() |
|
|
|||||||
![]() |
XML - detect duplicate element in SAX |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: n/a
|
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 |
|
|
|
#3 |
|
Posts: n/a
|
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 |
|