@@ -73,9 +73,9 @@ attrThrowXsd name elNode = maybeThrowXsd (M.lookup name $ elementAttributes elNo
73toElemsAndDatatypes :: XML.Cursor -> XSDMonad [XSD.Element]
73toElemsAndDatatypes :: XML.Cursor -> XSDMonad [XSD.Element]
74toElemsAndDatatypes cursor = do
74toElemsAndDatatypes cursor = do
75 elems <- traverse toElem (cursor $/ laxElement "element")
75 elems <- traverse toElem (cursor $/ laxElement "element")
76− datatypes <- traverse toDatatype (cursor $/ laxElement "complexType")
76+ datatypes <- traverse toComplexType (cursor $/ laxElement "complexType")
77 for_ datatypes $ \case
77 for_ datatypes $ \case
78− datatype@(ComplexType (Just name) _ _) -> tell (M.singleton name datatype)
78+ datatype@(ComplexType (Just name) _ _) -> tell (M.singleton name (TypeComplex datatype))
79 datatype@(ComplexType Nothing _ _) ->
79 datatype@(ComplexType Nothing _ _) ->
80 throwXsd $ "unnamed type ref for datatype: " <> show datatype
80 throwXsd $ "unnamed type ref for datatype: " <> show datatype
81 pure elems
81 pure elems
@@ -116,44 +116,49 @@ toElem cursor = do
117 throwXsd $ "[toElem] element expected, got: " <> show e
117 throwXsd $ "[toElem] element expected, got: " <> show e
119−-- | Returns 'Just element' if encounters an element,
120toDatatype :: Cursor -> XSDMonad Datatype
119toDatatype :: Cursor -> XSDMonad Datatype
121toDatatype cursor = do
120toDatatype cursor = do
122 case node cursor of
121 case node cursor of
123 NodeElement el -> case nameLocalName (elementName el) of
122 NodeElement el -> case nameLocalName (elementName el) of
124− "simpleType" -> do
123+ "simpleType" -> TypeSimple <$> toSimpleType cursor
125− error "implement simpleType"
124+ "complexType" -> TypeComplex <$> toComplexType cursor
127− let sequenceAxis = laxElement "sequence"
128− let choiceAxis = laxElement "choice"
129− let allAxis = laxElement "all"
130− if P.null (cursor $// sequenceAxis)
131− then if P.null (cursor $// choiceAxis)
132− then if P.null (cursor $// allAxis)
133− then throwXsd $ "No definition found for complexType: "
134− <> show (safeHead $ cursor $// laxElement "complexType")
136− childCursor <- maybeThrowXsd (safeHead $ cursor $// allAxis)
137− $ "More than one xs:all tag in: "
138− <> show (cursor $// laxElement "complexType")
139− let name = safeHead $ cursor $| attribute "name"
140− ComplexType name CTAll <$> toElemsAndDatatypes childCursor
142− childCursor <- maybeThrowXsd (safeHead $ cursor $// choiceAxis)
143− $ "More than one xs:choice tag in: "
144− <> show (cursor $// laxElement "complexType")
145− let name = safeHead $ cursor $| attribute "name"
146− ComplexType name CTChoice <$> toElemsAndDatatypes childCursor
148− childCursor <- maybeThrowXsd (safeHead $ cursor $// sequenceAxis)
149− $ "More than one xs:sequence tag in: "
150− <> show (cursor $// laxElement "complexType")
151− let name = safeHead $ cursor $| attribute "name"
152− ComplexType name CTSequence <$> toElemsAndDatatypes childCursor
153− e -> throwXsd $ "[toDatatype] xsd node not supported: " <> show e
125+ e -> throwXsd $ "[toDatatype] xsd node not supported: " <> show e
155 throwXsd $ "[toDatatype] element expected, got: " <> show e
127 throwXsd $ "[toDatatype] element expected, got: " <> show e
129+toSimpleType :: Cursor -> XSDMonad SimpleType
130+toSimpleType cursor = do
131+ error "TODO: implement toSimpleType"
133+toComplexType :: Cursor -> XSDMonad ComplexType
134+toComplexType cursor = do
135+ let sequenceAxis = laxElement "sequence"
136+ let choiceAxis = laxElement "choice"
137+ let allAxis = laxElement "all"
138+ if P.null (cursor $// sequenceAxis)
139+ then if P.null (cursor $// choiceAxis)
140+ then if P.null (cursor $// allAxis)
141+ then throwXsd $ "No definition found for complexType: "
142+ <> show (safeHead $ cursor $// laxElement "complexType")
144+ childCursor <- maybeThrowXsd (safeHead $ cursor $// allAxis)
145+ $ "More than one xs:all tag in: "
146+ <> show (cursor $// laxElement "complexType")
147+ let name = safeHead $ cursor $| attribute "name"
148+ ComplexType name CTAll <$> toElemsAndDatatypes childCursor
150+ childCursor <- maybeThrowXsd (safeHead $ cursor $// choiceAxis)
151+ $ "More than one xs:choice tag in: "
152+ <> show (cursor $// laxElement "complexType")
153+ let name = safeHead $ cursor $| attribute "name"
154+ ComplexType name CTChoice <$> toElemsAndDatatypes childCursor
156+ childCursor <- maybeThrowXsd (safeHead $ cursor $// sequenceAxis)
157+ $ "More than one xs:sequence tag in: "
158+ <> show (cursor $// laxElement "complexType")
159+ let name = safeHead $ cursor $| attribute "name"
160+ ComplexType name CTSequence <$> toElemsAndDatatypes childCursor
157toXsd :: Document -> Either SomeException XSD
162toXsd :: Document -> Either SomeException XSD
158toXsd doc = do
163toXsd doc = do
159 (el, dt) <- runWriterT $ toSchema (fromDocument doc)
164 (el, dt) <- runWriterT $ toSchema (fromDocument doc)