Roger Cigol 103 Posted May 17 I have a short sample XML file which is as follows <?xml version="1.0"?> <authors> <author> <name>abc</name> <posts> <items> <title lang="eng1">abc item 1</title> <content lang="eng2">abc item 1</content> </items> <items> <title lang="eng3">abc item 2</title> <content lang="eng4">abc item 2</content> </items> <items> <title lang="eng5">abc item 3</title> <content>abc item 3</content> </items> <items> <title>abc item 4</title> <content lang="eng6">abc item 4</content> </items> </posts> </author> </authors> I need a schema (ie a file *.xsd format) for this xml format. Schema creation tools I have tried don't seem to be able to handle the fact that nodes such as <title>...</title> contain both an attribute and text data. If I use a tool to create a schema *.xsd and then recreate a sample xml from the created schema I always find that the resulting xml created is missing either the attribute or the data, meaning the schema I have generated does NOT match my XML file. Can anyone create a schema that does correctly map to an XML file with nodes with both attribute and text data? I know it's not a delphi question (or a C++ Builder question) but I also know there are some XML gurus on Delphi Praxis that might be able to solve my problem very easily ! Thanks in anticipation Share this post Link to post
Lars Fosdal 1792 Posted May 17 From https://www.freeformatter.com/xsd-generator.html - "Salami Slice" design Does this look ok? <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="title"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute type="xs:string" name="lang" use="optional"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> <xs:element name="content"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute type="xs:string" name="lang" use="optional"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> <xs:element name="items"> <xs:complexType> <xs:sequence> <xs:element ref="title"/> <xs:element ref="content"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="name" type="xs:string"/> <xs:element name="posts"> <xs:complexType> <xs:sequence> <xs:element ref="items" maxOccurs="unbounded" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="author"> <xs:complexType> <xs:sequence> <xs:element ref="name"/> <xs:element ref="posts"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="authors"> <xs:complexType> <xs:sequence> <xs:element ref="author"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> Share this post Link to post
Roger Cigol 103 Posted May 17 Wow! super fast response. I wasn't aware of that useful site - so thanks for the link. I will try this xsd and see how I get on.... Thank you Lars. 1 Share this post Link to post