160 likes | 319 Views
XML Schema Lecture - 2013S -. Clinton E. White, Jr Professor of Accounting & MIS Lerner College of B&E University of Delaware. The XML Foundation. Many participants – an extended family! XML documents – carry data in context Each must be parsed into its component parts
E N D
XML Schema Lecture- 2013S - Clinton E. White, Jr Professor of Accounting & MIS Lerner College of B&E University of Delaware
The XML Foundation • Many participants – an extended family! • XML documents – carry data in context • Each must be parsed into its component parts • XML schemas – define the rules a class of documents must follow • Are used to define vocabularies and validate documents & their contents • XSLT – provide processing instructions • Is used to process XML documents • Namespaces – qualify elements & attributes • Differentiate & associate them with a URI • XPath … XLink … XQuery … • Warning: XML Processors are not designed equally!
UBL & XML schema Namespaces • <xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cbc="UBLCommonBasicComponents" xmlns:cac="UBLCommonAggregateComponents" xmlns=“UBLOrderDocument” targetNamespace="UBLOrderDocument"> • Also: elementFormDefault="qualified" attributeFormDefault="unqualified“
Namespaces(xmlns) • XML Namespaces: • A collection of elements and attributes for a particular purpose • Each XML namespace has a unique URI that differentiates it from all others • Each namespace is declared using “xmlns” • xmlns:xs="http://www.w3.org/2001/XMLSchema“ • xmlns:cbc="UBLCommonBasicComponents" • xmlns:cac="UBLCommonAggregateComponents“ • xmlns:us-gaap="http://xbrl.fasb.org/us-gaap/2012" • xmlns:ifrs="http://xbrl.ifrs.org/taxonomy/2012-03-29/ifrs" • Each namespace has its own recommendedprefix
UBL • UBL schemas: • All UBL reusable components and the common documents that are created using them are defined in XML schemas • The UBL schemas are the contents of the UBL library • We simply reference the elements and use them in our XML instance documents • UBL Invoice example
XML Schema • XML Schema • A language used to create XML schema documents • XML schema documents define elements & attributes for a specific purpose and the rules that a class of XML documents must follow • Define each element and each attribute that can appear in a document by giving each a name and a data type • Define the structure of the document • Define simple business rules
UBL cbc schema • Defines all of the simple elements in the UBL vocabulary: • <?xml version="1.0" encoding="UTF-8" ?> • <!-- File: UBLCommonBasicComponentsSchema.xml --> • <xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="UBLCommonBasicComponents" targetNamespace="UBLCommonBasicComponents" elementFormDefault="qualified" attributeFormDefault="unqualified"> • - <!-- Simple elements --> • <xs:element name="ID" type="xs:string" /> • <xs:element name="Name" type="xs:string" /> • <xs:element name="SalesOrderID" type="xs:string" /> • <xs:elementname="IssueDate" type="xs:date" /> • … …
UBL cac schema • The UBL Common Aggregate Components schema: • Imports the UBL Common Basic Components schema • Defines all complex UBL elements • <xs:element name="Party"> • <xs:complexType> • <xs:sequence> • <xs:element ref="PartyName" minOccurs="1" maxOccurs="1" /> • <xs:element ref="PostalAddress" minOccurs="1" maxOccurs="1" /> • <xs:element ref="Contact" minOccurs="0" maxOccurs=“unbounded" /> • </xs:sequence> • </xs:complexType> • </xs:element> • All complex UBL elements are defined in a schema by giving them a unique name, a complexType, and defining their contents (i.e., other complex or simple elements)
Schemas • XMLNS - in root element: • xmlns:cbc="UBLCommonBasicComponents“ • xmlns:cac="UBLCommonAggregateComponents“ • Import namespaces in schema document & tie them to a schemaLocation: • <xs:importnamespace="UBLCommonBasicComponents" schemaLocation="http://www.buec.udel.edu/whitec/UBLCommonBasicComponents/UBLCommonBasicComponentsSchema.xsd"/> • <xs:importnamespace="UBLCommonAggregateComponents" schemaLocation="http://www.buec.udel.edu/whitec/UBLCommonAggregateComponents/UBLCommonAggreagteComponentsSchema.xsd"/> • Usecbcandcacnamespaceprefixeswhereappropriate in the schema document
Well-formed vs. Valid • What is the difference between a Well-formed and a Valid XML document?
Valid XML Documents XML document Valid XML document XML Validating Processor XML schema document Imported XML schema documents
Schema Validator • Does the XML document follow the rules specified in its schema? • http://tools.decisionsoft.com/schemaValidate/Validate • Warning: • Not all validators are created equal!
Financial Reporting • A business entity: • Creates its financial reports in XBRL format • Uses elements defined in the U.S. GAAP XBRL taxonomy schemas • Uses elements defined in its own extension taxonomy schemas • Validates the XBRL instance documents • Submits both the taxonomy schemas & the instance documents to the SEC as a “package” • The SEC • Validates the instance documents • Files both the XBRL instance docs. & the taxonomy schemas in the EDGAR (formerly IDEA) database
XBRL Instance Documents • Well-formed and valid XBRL instance documents: • xbrl – the root element • schemaRef – the first child element • context – must have at least one • unit – must have at least one if numeric items are being reported • item – must have at least one reported item
Assignment(Due 3/22/2013) • Exercise 3-2 • A UBL Invoice document schema • Include your name in a comment at the top of the document • <!--your name--> • Validate your UBL Invoice document against your UBL Invoice schema