@@ -160,18 +160,19 @@ parseSimpleType c = do
160160 unionAxis <- makeElemAxis "union"
161161 case (c $/ restrictionAxis, c $/ listAxis, c $/ unionAxis) of
162162 ([e], [], []) -> Xsd.AtomicType
163− <$> parseRestriction e
163+ <$> parseSimpleRestriction e
164164 <*> parseAnnotations c
165165 ([], [l], []) -> Xsd.ListType
166166 <$> parseList l
167167 <*> parseAnnotations c
168− -- TODO implement me
169− ([], [], [_]) -> parseError c "Not implemented: union"
168+ ([], [], [u]) -> Xsd.UnionType
169+ <$> parseUnion u
170+ <*> parseAnnotations c
170171 _ -> parseError c "Expected exactly of of restriction, list or union"
171172
172173-- | Restriction for simple type
173−parseRestriction :: Cursor -> P Xsd.Restriction
174−parseRestriction c = do
174+parseSimpleRestriction :: Cursor -> P Xsd.SimpleRestriction
175+parseSimpleRestriction c = do
175176 -- XXX: generalaze RefOr parsing
176177 tp <- case anAttribute "base" c of
177178 Nothing -> do
@@ -184,9 +185,9 @@ parseRestriction c = do
184185
185186 constraints <- parseConstrains c
186187
187− return Xsd.Restriction
188− { Xsd.restrictionBase = tp
189− , Xsd.restrictionConstraints = constraints
188+ return Xsd.SimpleRestriction
189+ { Xsd.simpleRestrictionBase = tp
190+ , Xsd.simpleRestrictionConstraints = constraints
190191 }
191192
192193parseConstrains :: Cursor -> P [Xsd.Constraint]
@@ -207,6 +208,15 @@ parseList c =
207208 _ -> parseError c "Multiple types"
208209 Just t -> Xsd.Ref <$> makeQName c t
209210
211+parseUnion :: Cursor -> P [Xsd.RefOr Xsd.SimpleType]
212+parseUnion c =
213+ case anAttribute "memberTypes" c of
214+ Just list ->
215+ mapM (fmap Xsd.Ref . makeQName c) (Text.splitOn " " list)
216+ Nothing -> do
217+ simpleTypeAxis <- makeElemAxis "simpleType"
218+ mapM (fmap Xsd.Inline . parseSimpleType) (c $/ simpleTypeAxis)
219+
210220parseComplexType :: Cursor -> P Xsd.ComplexType
211221parseComplexType c = do
212222 annotations <- parseAnnotations c
@@ -237,14 +247,29 @@ parsePlainContent c = do
237247 }
238248
239249parseSimpleContent :: Cursor -> P Xsd.SimpleContent
240−parseSimpleContent c = parseError c "not implemented"
250+parseSimpleContent c = do
251+ restrictionAxis <- makeElemAxis "restriction"
252+ extenstionAxis <- makeElemAxis "extension"
253+ case (c $/ restrictionAxis, c $/ extenstionAxis) of
254+ ([r], []) -> Xsd.SimpleContentRestriction <$> parseSimpleRestriction r
255+ ([], [e]) -> Xsd.SimpleContentExtension <$> parseSimpleExtension e
256+ _ -> parseError c "Expected one of restriction or extension"
257+
258+parseSimpleExtension :: Cursor -> P Xsd.SimpleExtension
259+parseSimpleExtension c = handleNamespaces c $ do
260+ base <- theAttribute "base" c >>= makeQName c
261+ attributes <- parseAttributes c
262+ return Xsd.SimpleExtension
263+ { Xsd.simpleExtensionBase = base
264+ , Xsd.simpleExtensionAttributes = attributes
265+ }
241266
242267parseComplexContent :: Cursor -> P Xsd.ComplexContent
243268parseComplexContent c = do
244269 restrictionAxis <- makeElemAxis "restriction"
245270 extenstionAxis <- makeElemAxis "extension"
246271 case (c $/ restrictionAxis, c $/ extenstionAxis) of
247− ([r], []) -> parseError r "not implemented"
272+ ([r], []) -> Xsd.ComplexContentRestriction <$> parseComplexRestriction r
248273 ([], [e]) -> Xsd.ComplexContentExtension <$> parseComplexExtension e
249274 _ -> parseError c "Expected one of restriction or extension"
250275
@@ -259,6 +284,17 @@ parseComplexExtension c = handleNamespaces c $ do
259284 , Xsd.complexExtensionAttributes = attributes
260285 }
261286
287+parseComplexRestriction :: Cursor -> P Xsd.ComplexRestriction
288+parseComplexRestriction c = handleNamespaces c $ do
289+ base <- theAttribute "base" c >>= makeQName c
290+ attributes <- parseAttributes c
291+ model <- parseModelGroup c
292+ return Xsd.ComplexRestriction
293+ { Xsd.complexRestrictionBase = base
294+ , Xsd.complexRestrictionModel = model
295+ , Xsd.complexRestrictionAttributes = attributes
296+ }
297+
262298parseModelGroup :: Cursor -> P (Maybe Xsd.ModelGroup)
263299parseModelGroup c = do
264300 sequenceAxis <- makeElemAxis "sequence"
@@ -293,24 +329,33 @@ parseAttributes c = do
293329
294330parseAttribute :: Cursor -> P Xsd.Attribute
295331parseAttribute c = do
296− name <- theAttribute "name" c >>= makeTargetQName
297332 use <- parseUseAttribute c
298−
299− -- XXX: generalaze RefOr parsing
300− tp <- case anAttribute "type" c of
301− Nothing -> do
302− simpleTypeAxis <- makeElemAxis "simpleType"
303− case c $/ simpleTypeAxis of
304− [s] -> Xsd.Inline <$> parseSimpleType s
305− [] -> parseError c "Attribute should have type"
306− _ -> parseError c "Multiple simple types"
307− Just t -> Xsd.Ref <$> makeQName c t
308−
309− return Xsd.Attribute
310− { Xsd.attrName = name
311− , Xsd.attrUse = use
312− , Xsd.attrType = tp
313− }
333+ case (anAttribute "name" c, anAttribute "ref" c) of
334+ (Just n, Nothing) -> do
335+ name <- makeTargetQName n
336+ tp <- case anAttribute "type" c of
337+ Nothing -> do
338+ simpleTypeAxis <- makeElemAxis "simpleType"
339+ case c $/ simpleTypeAxis of
340+ [s] -> Xsd.Inline <$> parseSimpleType s
341+ [] -> return (Xsd.Ref anySimpleType)
342+ _ -> parseError c "Multiple simple types"
343+ Just t -> Xsd.Ref <$> makeQName c t
344+ return $ Xsd.InlineAttribute $ Xsd.AttributeInline
345+ { Xsd.attributeInlineName = name
346+ , Xsd.attributeInlineUse = use
347+ , Xsd.attributeInlineType = tp
348+ }
349+ (Nothing, Just r) -> do
350+ ref <- makeQName c r
351+ return $ Xsd.RefAttribute $ Xsd.AttributeRef
352+ { Xsd.attributeRefRef = ref
353+ , Xsd.attributeRefUse = use
354+ }
355+ _ -> parseError c "Should be either name or ref"
356+ where
357+ anySimpleType =
358+ Xsd.QName (Just (Xsd.Namespace Xsd.schemaNamespace)) "anySimpleType"
314359
315360parseUseAttribute :: Cursor -> P Xsd.Use
316361parseUseAttribute c = case anAttribute "use" c of