talsnir Posted March 4, 2007 Share Posted March 4, 2007 Hello All,As I am stepping my first steps in XSD world I am encountering some difficulties. I guess that for a more experienced programmer my problem will look very easy and will be solved in no time but I can't see what I am doing wrong, so please help!I am trying to establish a standartd validation process for my XML file (ReportsConfig.xml). I've built in a corresponding schema (ReportsConfig.xsd), I've followed the instructions described in the w3schools tutorial but I still have problems.The reportsConfig XML file should contain a root element reports. The reports element should contain at least one report element that should contain at least one column element and a set of specific attibutes.Here is the schema: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:attribute name="id" type="xs:string"/> <xs:attribute name="label" type="xs:string"/> <xs:attribute name="description" type="xs:string"/> <xs:attribute name="type"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="query"/> <xs:enumeration value="query_keywords"/> <xs:enumeration value="query_no_results"/> <xs:enumeration value="products"/> <xs:enumeration value="biz_scoring"/> <xs:enumeration value="report_mvt"/> <xs:enumeration value="report_rules_summary"/> <xs:enumeration value="report_rules_templates"/> <xs:enumeration value="report_rules_triggered"/> <xs:enumeration value="report_builiding_blocks"/> <xs:enumeration value="report_metric_policy"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="pageSize"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:minInclusive value="0"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="topRecords"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:minInclusive value="0"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="sortOrder"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:enumeration value="1"/> <xs:enumeration value="2"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="exportable" type="xs:boolean"/> <xs:attribute name="exportSize"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:minInclusive value="0"/> <xs:maxInclusive value="65535"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="alertable" type="xs:boolean"/> <xs:attribute name="alertSize"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:minInclusive value="0"/> <xs:maxInclusive value="65535"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="searchable" type="xs:boolean"/> <xs:attribute name="hidden" type="xs:boolean"/> <xs:attribute name="pixelWidth"> <xs:simpleType> <xs:restriction base="xs:integer"> <xs:minInclusive value="0"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="dataType"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="number"/> <xs:enumeration value="percent"/> <xs:enumeration value="rank"/> <xs:enumeration value="string"/> <xs:enumeration value="date"/> <xs:enumeration value="bar"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="filterType"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="number"/> <xs:enumeration value="refine"/> <xs:enumeration value="category"/> <xs:enumeration value="text"/> <xs:enumeration value="date"/> <xs:enumeration value="radio"/> <xs:enumeration value="enum"/> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="format" type="xs:string"/> <!--Modification is Required !--> <xs:attribute name="sortColumn" type="xs:string"/> <xs:element name="reports"> <xs:complexType> <xs:sequence> <xs:element name="report" minOccurs="1" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="column" minOccurs="1" maxOccurs="unbounded"> <xs:complexType> <xs:attribute ref="id" use="required"/> <xs:attribute ref="label" use="required"/> <xs:attribute ref="description" use="optional"/> <xs:attribute ref="hidden" use="optional"/> <xs:attribute ref="searchable" use="optional"/> <xs:attribute ref="pixelWidth" use="optional"/> <xs:attribute ref="exportable" use="optional"/> <xs:attribute ref="alertable" use="optional"/> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute ref="id" use="required"/> <xs:attribute ref="label" use="required"/> <xs:attribute ref="description" use="optional"/> <xs:attribute ref="hidden" use="optional"/> <xs:attribute ref="pixelWidth" use="optional"/> <xs:attribute ref="searchable" use="optional"/> <xs:attribute ref="exportable" use="optional"/> <xs:attribute ref="alertable" use="optional"/> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> and here is the XML file: <?xml version="1.0" encoding="UTF-8"?><reports> <report id="products" label="Products" type="products" pageSize="40" topRecords="200" sortOrder="2" sortColumn="profit_margin" exportable="true" exportSize="1000" alertable="true" alertSize="200"> <columns> ... </columns> </report></reports> The problem is that everytime I am trying to validate the XML file in XML SPY I get the error message: "Root Element reports is not defined in dtd/schema". But it does present, I specifically added an element called reports to the schema - then what is going on?Any help will be highly appriciated. Thanks again ! Link to comment Share on other sites More sharing options...
craigewens Posted March 23, 2007 Share Posted March 23, 2007 At first glance you are missing the XML declaration at the start of your schema.http://www.w3schools.com/schema/schema_howto.asp scroll down to get to the title "An XML Schema" Link to comment Share on other sites More sharing options...
boen_robot Posted March 24, 2007 Share Posted March 24, 2007 I'm not getting THAT error using any of the validators included in Stylus Studio. I do however see your XML is not valid, because you use attributes you haven't defined... not for the "report" element anyway.The attributes are "type", "pageSize", "topRecords", "sortOrder", "sortColumn", "exportSize" and "alertSize". Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now