tag:blogger.com,1999:blog-19075986035956834312024-02-08T07:08:39.755-08:00An Interweb BlogStephen D Greenhttp://www.blogger.com/profile/11733910745267236574noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-1907598603595683431.post-9257235943704191562023-09-18T01:17:00.002-07:002023-09-18T01:17:19.617-07:00An Organisation’s Online Presence<p> <span style="-webkit-text-size-adjust: auto; font-family: UICTFontTextStyleBody; font-size: 23px;">Foundations are so vital with most buildings. No less so with the extension of any organisation towards use of the Internet and the Web. It is a big deal when a company has a public face in any way and no less so than on the Web. Foundations used to be formed in this regard by employing Web-savvy developers, specialists in the various requirements of having a website, and a web master, to oversee it all and manage the critical tasks such as security monitoring. They would be competent in security, protocols, web servers, and the workings of web sites and the architecture behind them. Nowadays it would need to include expertise in the Cloud too.</span><span style="-webkit-text-size-adjust: auto; font-family: UICTFontTextStyleBody; font-size: 23px;"> </span> <span style="-webkit-text-size-adjust: auto; font-family: UICTFontTextStyleBody; font-size: 23px;">Yet is this being eroded? Is it taken for granted nowadays that the Web is deskilled. A technically minded enthusiastic teen can set themselves up in the Cloud and Chat GPT can guide them in producing a web site. Why then bother with employing specialists.</span><span style="-webkit-text-size-adjust: auto; font-family: UICTFontTextStyleBody; font-size: 23px;"> </span></p><p class="p2" style="-webkit-text-size-adjust: auto; font-size: 23px; font-stretch: normal; line-height: normal; margin: 0px; min-height: 29px;"><span class="s1" style="font-family: UICTFontTextStyleBody;"></span><br /></p><p class="p1" style="-webkit-text-size-adjust: auto; font-size: 23px; font-stretch: normal; line-height: normal; margin: 0px;"><span class="s1" style="font-family: UICTFontTextStyleBody;">The danger of venturing into the Web from the safety of the corporate enterprise intranet is that mistakes are very public. Search engines pick up your expired links. Anyone can click those links and many know how to set up a script to click them repeatedly or worse and possibly overload your servers. It is not a safe place. Errors can be detrimental to the company reputation. Excessive errors, not managed but allowed to continue, can even result in loss of indemnity insurance and mean the company can lose its ability to operate. </span></p><p class="p2" style="-webkit-text-size-adjust: auto; font-size: 23px; font-stretch: normal; line-height: normal; margin: 0px; min-height: 29px;"><span class="s1" style="font-family: UICTFontTextStyleBody;"></span><br /></p><p class="p1" style="-webkit-text-size-adjust: auto; font-size: 23px; font-stretch: normal; line-height: normal; margin: 0px;"><span class="s1" style="font-family: UICTFontTextStyleBody;">Finding skilled developers with sufficient foundational knowledge might be a challenge but lack of awareness of this need, and naivety among even the director level managers of a company might threaten the foundations of maintaining a public Web presence, an outward face in the cyber world. <span class="Apple-converted-space"> </span>The Cloud won’t solve it. It is an internal issue of the architecture of the IT dimension of an organisation no matter its size. </span></p><p class="p2" style="-webkit-text-size-adjust: auto; font-size: 23px; font-stretch: normal; line-height: normal; margin: 0px; min-height: 29px;"><span class="s1" style="font-family: UICTFontTextStyleBody;"></span><br /></p><p class="p1" style="-webkit-text-size-adjust: auto; font-size: 23px; font-stretch: normal; line-height: normal; margin: 0px;"><span class="s1" style="font-family: UICTFontTextStyleBody;">It is vital to follow normal practices. The knowledge required to roll your own architecture and maintain it and provide skills to maintain it is too great today. The whole Web community is designing how things are done and providing the solutions necessary for an organisation to use the Web in today’s world. The developers need to keep to this script. There is safety in numbers. It is well that a script prompter exists for all to use which is AI. More than just the developer forums exist today. We can ask our favourite forum but ask our favourite AI too. This keeps us easily connected with the hive mind needed to produce and maintain a Web presence whether on prem or Cloud. The users of our Web facilities out in the wild are owed an easy and gentle experience that does not alarm them or fray their nerves. More-so their business and personal interests must not be put at risk when they interact with our organisation online. To ensure this we all the more need to follow industry practices and not try to do our own thing. </span></p><p class="p2" style="-webkit-text-size-adjust: auto; font-size: 23px; font-stretch: normal; line-height: normal; margin: 0px; min-height: 29px;"><span class="s1" style="font-family: UICTFontTextStyleBody;"></span><br /></p><p class="p1" style="-webkit-text-size-adjust: auto; font-size: 23px; font-stretch: normal; line-height: normal; margin: 0px;"><span class="s1" style="font-family: UICTFontTextStyleBody;">The Cloud too is a party, a stakeholder, when we use it. Loose ends which can be wilfully exploited online or unwittingly tripped over, these can damage other users of the Cloud and if allowed to go unmanaged might even cause the Cloud provider to refuse us their services. </span></p><p class="p2" style="-webkit-text-size-adjust: auto; font-size: 23px; font-stretch: normal; line-height: normal; margin: 0px; min-height: 29px;"><span class="s1" style="font-family: UICTFontTextStyleBody;"></span><br /></p><p class="p1" style="-webkit-text-size-adjust: auto; font-size: 23px; font-stretch: normal; line-height: normal; margin: 0px;"><span class="s1" style="font-family: UICTFontTextStyleBody;">We need to keep an eye on our foundations. To ignore this might leave even the better developers at a loss to make good on the loss of a sound bed rock on which to build the company outward online face. That would not be good for the reputation of the company and the trust of its clients and customers, and other stakeholders affected. </span></p>Stephen D Greenhttp://www.blogger.com/profile/11733910745267236574noreply@blogger.com0tag:blogger.com,1999:blog-1907598603595683431.post-2505954079531982252011-04-10T23:48:00.000-07:002011-04-11T13:23:54.374-07:00Document Engineering: Test Assertions Example<span style="font-family: Verdana, sans-serif;">I was asked to clarify my previous blog posting from yesterday with some examples, so I'll give it a go.</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">A simple example is an OASIS Universal Business Language (UBL) invoice's so-called 'calculation model' (an example of rules showing how calculations in the invoice are to be made). The invoice has all kinds of totals and amounts so the way you calculate totals from the amounts is important to get right.</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">In TAML (Test Assertions Markup Language) I can write the rules as test assertions but using XPath so they can be executed against the XML invoice:</span><br />
<span style="font-family: Verdana, sans-serif;">...</span><br />
<span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: "Courier New", Courier, monospace;"><taml:testAssertion id="IN1" name="Invoice" enable="true"><br /> <taml:normativeSource>U2ICMDraft5Rule1:</span><br />
<span style="font-family: "Courier New", Courier, monospace;">"To be a conforming UBL 2 invoice the document MUST be valid according to a standard UBL 2 Invoice schema."</taml:normativeSource><br /> <taml:target type="document" idscheme="'document'">/</taml:target><br /> <taml:predicate>count(//in:Invoice) ge 1</taml:predicate><br /> <taml:prescription level="mandatory"/><br /> <taml:report label="failed" message="Not a standard UBL 2 invoice">The file does not contain a standard UBL 2<br />invoice.</taml:report><br /> </taml:testAssertion><br /><br /> <taml:testAssertion id="INTOT1" name="LineExtensionAmount (1)" enable="true"><br /> <taml:normativeSource>U2ICMDraft5Rule2:</span><br />
<span style="font-family: "Courier New", Courier, monospace;">"The 'LineExtensionAmount' in the invoice 'LegalMonetaryTotal' SHOULD equal the sum of all 'LineExtensionAmount's in all of the invoice lines."</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> </taml:normativeSource><br /> <taml:target type="total"<br />idscheme="'invoice-total'"><br />/in:Invoice/cac:LegalMonetaryTotal</taml:target><br /> <taml:prerequisite>(count(distinct-values(</span><a href="http://www.blogger.com/"><span style="font-family: "Courier New", Courier, monospace;">//*/@currencyID</span></a><span style="font-family: "Courier New", Courier, monospace;">)) eq<br />1)</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> </taml:prerequisite><br /> <taml:predicate></span><br />
<span style="font-family: "Courier New", Courier, monospace;">number(./cbc:LineExtensionAmount) eq<br />sum(/in:Invoice/cac:InvoiceLine/cbc:LineExtensionAmount)</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> </taml:predicate><br /> <taml:prescription level="preferred"/><br /> <taml:report label="failed" message="Error in Line Extension Amount"></span><br />
<span style="font-family: "Courier New", Courier, monospace;">The line extension total is not the sum of the invoice lines'<br />line extension amounts.</span><br />
<span style="font-family: Verdana, sans-serif;"><span style="font-family: "Courier New", Courier, monospace;"> </taml:report><br /> </taml:testAssertion></span>...</span><br />
<br />
<span style="font-family: Verdana;">These are just two rules in an example set of rules.</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">If I use XML Schema (XSD) 1.1 to apply the assertions (effectively as test cases) by combining them with a schema (see previous blog posting) I run into some immediate problems:</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">1) Ideally I need to use a schema which targets a UBL invoice but a) my UBL invoice already has a schema b) my UBL invoice schema has some design rules which might make it tricky changing a globally defined element into a locally defined one</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">2) Assuming I can write my own schema in XSD 1.1, and can find a way to define some elements globally, if the assertion(s) targeting it allow this, and some elements locally if the assertions targeting those elements demand<br />it (e.g. have relevance only to certain contexts for that element)</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">3) Does every assertion map to one or more elements? I need to be able to turn any failed test of one assertion into a report refering to the one TA (by its ID). Can I do that?</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">4) How do I apply prerequisites? </span><span style="font-family: Verdana, sans-serif;">I could add them to the predicate perhaps but it makes it quite complex. The logic needs to be that if </span><span style="font-family: "Courier New", Courier, monospace;">(count(distinct-values(</span><a href="http://www.blogger.com/"><span style="font-family: "Courier New", Courier, monospace;">//*/@currencyID</span></a><span style="font-family: Verdana, sans-serif;"><span style="font-family: "Courier New", Courier, monospace;">)) eq 1)</span>then the predicate applies, else it does not apply so it might be a little more complex than I'd like. </span><span style="font-family: Verdana, sans-serif;">Now this doesn't give me a mapping to my test assertion so I need to add the TA id somewhere - in a report or annotation, say (can I do that in XML Schema 1.1 ?). </span><br />
<br />
<span style="font-family: Verdana, sans-serif;">That's how I'd like it to work but</span><span style="font-family: Verdana, sans-serif;"> I'm told there is a hitch to this. The XML Schema 1.1 assert cannot lookup values from another part of the document. Duh! Still, I can handle it perhaps. <strong>I need to take all the values from the UBL that I want to test, calculate the appropriate totals, do the appropriate lookups and put the results in a special XML file - I might call it the provisional report file. It is then this file's markup, specially designed to support my test assertions, which I define using XML Schema 1.1. </strong></span><br />
<br />
<span style="font-family: Verdana;">e.g.</span><br />
<span style="color: black; font-family: "Courier New", Courier, monospace;"><?xml version="1.0" encoding="UTF-8"?></span><br />
<span style="color: black; font-family: "Courier New", Courier, monospace;"><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><br />
<xs:element name="InvoiceCalculationModelReport"><br />
<xs:complexType><br />
<xs:sequence><br />
<xs:element name="IN1"><br />
<xs:complexType><br />
<xs:sequence><br />
<xs:element name="InvoiceCount"><br />
<xs:simpleType><br />
<xs:restriction base="xs:int"><br />
<xs:assertion test="$value ge 1"/><br />
</xs:restriction><br />
</xs:simpleType><br />
</xs:element><br />
</xs:sequence><br />
</xs:complexType><br />
</xs:element><br />
<xs:element name="INTOT1"><br />
<xs:complexType><br />
<xs:sequence><br />
<xs:element name="DistinctCurrencyCount"><br />
<xs:simpleType><br />
<xs:restriction base="xs:int"><br />
<xs:assertion test="$value eq 1"/><br />
</xs:restriction><br />
</xs:simpleType><br />
</xs:element><br />
<xs:element name="LegalMonetaryTotalLineExtensionAmount"><br />
<xs:simpleType><br />
<xs:restriction base="xs:int"/><br />
</xs:simpleType><br />
</xs:element><br />
<xs:element name="SumOfLineExtensionAmounts"><br />
<xs:simpleType><br />
<xs:restriction base="xs:int"/><br />
</xs:simpleType><br />
</xs:element><br />
</xs:sequence><br />
<xs:assert test="SumOfLineExtensionAmounts eq LegalMonetaryTotalLineExtensionAmount"/><br />
</xs:complexType><br />
</xs:element></span><br />
<span style="color: black; font-family: "Courier New", Courier, monospace;"> <!-- ... --><br />
</xs:sequence><br />
</xs:complexType><br />
</xs:element><br />
</xs:schema></span><br />
<span style="color: #0064c8;"></span><br />
<span style="font-family: Verdana, sans-serif;">Then it is a relatively simple matter to extract values using code, database or XSLT (with help from the TA XPaths perhaps if the latter is used) from the target UBL invoice into a provisional report file which is validated by this schema. The report file would, in this example with just a few test assertions, look like the following</span><span style="font-family: "Courier New", Courier, monospace;">:</span><br />
<br />
<span style="color: black; font-family: "Courier New", Courier, monospace;"><?xml version="1.0" encoding="UTF-8"?></span><br />
<span style="color: black; font-family: "Courier New", Courier, monospace;"><InvoiceCalculationModelReport><br />
<IN1><br />
<InvoiceCount>1</InvoiceCount><br />
</IN1><br />
<INTOT1><br />
<DistinctCurrencyCount>1</DistinctCurrencyCount>
<LegalMonetaryTotalLineExtensionAmount>100</LegalMonetaryTotalLineExtensionAmount><br />
<SumOfLineExtensionAmounts>100</SumOfLineExtensionAmounts><br />
</INTOT1><br />
<!-- ... --><br /></InvoiceCalculationModelReport></span><br />
<span style="color: #000096;"></span><br />
<span style="font-family: Verdana, sans-serif;">The added advantage is that I can then get results into my provisional report file whatever the target system, even for a non-software system. The final output is the final report file which reports pass/fail/irrelevant of the like for each assert or better still, for each TA.</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">In the open source tool for executing test assertions written in XPath, called Tamelizer (hosted on Google Code) there is a similar way to handle such scenarios. The Test Assertions (TAs) are written in TAML and there is a provisional markup written describing the features of the targeted product. The executable TAs are written in terms of the markup used to describe the product features and executed against that marked up description document. </span><br />
<br />
<span style="font-family: Verdana, sans-serif;">Here's a shot at how it would work for a target which is a mechanical widget with some features as follows </span><br />
<span style="font-family: Verdana, sans-serif;">1) red button on top<br />2) number of batteries = 2<br />3) voltage = 6V<br />4) alarm sound = continuous<br />5) country of destination = UK</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">The spec might have some TAs written for it such as</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">TA1: if there is a 6V battery then the button on top MUST be red<br />TA2: there MUST be at least 1 battery<br />TA3: if there are two batteries then their voltage MUST be 3V<br />TA4: if the country of destination for the widget is US then the<br />button on the widget MUST be blue</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">The features can be marked up with some XML. The test cases are written as the TA expressions but in terms of the markup as XPaths</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">Now here the XSD 1.1 comes in. The markup for the features is defined now in XSD 1.1 so that the test cases can be added into the asserts of the respective elements.</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">The markup might be</span><br />
<br />
<span style="font-family: "Courier New", Courier, monospace;"><widget><br /><buttonColour>red</buttonColour><br /><batteries><br /><number>2</number><br /><voltage units="Volts">6</voltage><br /></batteries><br /><destination>UK</destination><br />...<br /></widget></span><br />
<br />
<span style="font-family: Verdana, sans-serif;">The expession of a TA in terms of the above might be</span><br />
<br />
<span style="font-family: "Courier New", Courier, monospace;"><TA id="TA2"><predicate language="XPath">/widget/batteries/number gt; 1</predicate>...</TA></span><br />
<br />
<span style="font-family: Verdana, sans-serif;">The schema definition for batteries might be</span><br />
<br />
<span style="font-family: "Courier New", Courier, monospace;"><xsd:element name="batteries"><br />...<br /><xsd:assert>number &gt; 1</xsd:assert><br />...<br /></xsd:element></span><br />
<span style="font-family: "Courier New", Courier, monospace;"><br /></span><br />
<span style="font-family: Verdana, sans-serif;">Now the point is that the assertion needs to meet some criteria of TAs. One is that the report needs to refer to exactly one TA by its Id. There might be several TAs applying to the same element so the XSD 1.1 might or might not meet this requirement. This relates to the fact that a TA should itself map to a single requirement in the spec. The TA needs to be self-contained too so that this mapping is unambiguous.</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">If there is a prerequisite for a TA then there needs to be a corresponding prerequisite for the assertion in the schema.</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">It gets complex when I have a single prerequisite for many TAs together but I can just apply the same prerequisite logic to each and every assertion individually. If I do though the XPaths of testing might take longer. </span><span style="font-family: Verdana, sans-serif;">If I structure the schema though and the if I have control over the features markup too I might be able to put my prerequisites on ancestor elements so that descendants' assertions are irrelevant if those higher assertions fail. Now this is where portability might apply. I really want to make each assertion composable and composability makes portability desirable. Say I have many profles for my spec: I might want some TAs to be transferred between those profiles. This might mean I have to make the assertions in the schema portable for those TAs so that I can move them from a schema for one profile into a schema for another one. Having those higher level assertions might hinder this: It might be better to have any prereqs added to every assertion where it applies so that I can always copy that element with its prerequisites and predicate expressed all in the one assertion. That is really my main point. Plus I tend to think the TAs are going to be each self-contained and atomic so the assertions in the schema relating to them might need to be too.</span><br />
<br />
<span style="font-family: Verdana;">Now I can go back to the real world example of the UBL </span><span style="font-family: Verdana;">invoice test assertions and instead of writing an XSD 1.1 </span><span style="font-family: Verdana;">schema again for UBL, I can write a schema for a list of </span><span style="font-family: Verdana;">elements to take values extracted from a UBL invoice - the </span><span style="font-family: Verdana;">tax totals, line totals, etc. I can derive it from an invoice using </span><span style="font-family: Verdana;">XSLT, say, or just programming code. Now the schema for </span><span style="font-family: Verdana;">this totals document can itself be written in XML Schema 1.1 </span><span style="font-family: Verdana;">and can be modelled along the lines of my set of test assertions. </span><span style="font-family: Verdana;">It can then take XPath Boolean expressions derived from my </span><span style="font-family: Verdana;">Test Assertions (if the latter are already written in XPath I might </span><span style="font-family: Verdana;">only want to combine the prerequisite and predicate expressions </span><span style="font-family: Verdana;">to get my XSD 1.1 assert expression). Then I can execute the </span><span style="font-family: Verdana;">schema against the totals in their XML markup and, using say </span><span style="font-family: Verdana;">a tool like Saxon which can read and execute the XSD 1.1, obtain a list of </span><span style="font-family: Verdana;">any deviations from the rules.</span><br />
<br />
<span style="font-family: Verdana;">Not exactly keeping it simple but sometimes it has to be just </span><span style="font-family: Verdana;">a little complex to accomplish what we need, just no more </span><span style="font-family: Verdana;">complex than it needs to be, hopefully.</span><br />
<br />
<span style="font-family: Verdana;">I have to say though, even when compared to Schematron, another assertion-based schema language based on XPath and executed using a two-step XSLT approach, I do rather prefer Tamelizer, the Google Code project, with XPath expressions in executable TAML test assertions. Maybe it won't get as wide use as XML Schema 1.1 but it is just right, I think, for test cases for XML document targets. It takes more skill to write all of the reasoning into the TAML XPath expressions but they execute against the actual target XML so for this kind of target it is worth that little more struggle getting the XPaths right. The prerequisite facility makes it all the more satisfactory in my view.</span>Stephen D Greenhttp://www.blogger.com/profile/11733910745267236574noreply@blogger.com0tag:blogger.com,1999:blog-1907598603595683431.post-25218281417835079532011-04-10T13:30:00.000-07:002011-04-10T13:30:58.678-07:00Document Engineering: Test Assertions and XML Schema Assertions<span style="font-family: Verdana, sans-serif;">Computer software does sometimes require some engineering discipline to keep in running smoothly. Software sometimes needs to be spoon fed information and sometimes that information comes in the form of documents similar to those read by humans (invoices can be sent from computer system to computer system to simplify and improve the efficiency of business transactions, perhaps over the Internet). Sometimes humans need to use software to write documents and software to read those same documents. The software used to write a document might be different from the software used to read it (Word at one end and Open Office at the other, say). On the Internet, web browsers need to read websites written and served up with various kinds of software packages from various software producers. All this makes it important at times to apply some engineering practices to ensure things work well. One such practice is the process from specification to conformance test or interoperability test. The specification for, say, a document might require that software reading the document handle it in this way or that way. It might also say how the document is to be written, perhaps using one of the many markup languages such as those which are based on the W3C standards authority's eXtensible Markup Language (XML). One software engineering practice used over and over for decades of computer system history is the production of many test assertions corresponding to statements in a specification. These are atomic restatements which get numbered or indexed in some way so that a test based on the spec can be tied to an individual statement in the spec. The test assertions are a bit like a special engineering index for the spec to help with testing.</span><br />
<br />
<span style="font-family: Verdana;">Now a test assertion exists so that testers know that there is something particular which they ideally ought to make a special point of testing. They can refer to this test assertion in their test so that a failure of a component being tested can be tied in a test report to the exactly relevant item in the spec. Not complicated really. They often call the individual tests 'test cases'. Large, complicated systems can involve many thousands of test assertions (for large, complicated specifications, of course) and similarly large numbers of test cases based on these assertions. The test assertions could fill a fair bit of a database or a pretty big file of data, depending how they are stored. Then you have to be able to cater for various versions of the specs and various versions of the software or documents being tested. Simplicity might help make it all manageable and help real people keep track of it all. </span><br />
<br />
<span style="font-family: Verdana;">Now I have an interest at the moment in a particular technology and I'd like to explore an idea that for XML document testing, and maybe any kind of testing when the tests are documented first as XML documents, you can either write the test using this certain technology or turn test results into test reports using this technology when the tests themselves are run some other way. The technology in question is W3C XML Schema version 1.1. This allows an assertion a bit like a test assertion to be written using a special syntax for expressions relating to an XML document to be inserted into the middle of a definition of a particular part of that XML document. Test assertions targeting XML documents do not have to be expressed so that they can be executed as a test applied to the XML documents. There are some well known examples of where they are written this way but here (some WSI web services specs have such test assertions) really these test assertions are doubling up as test cases. I reckon the assertion feature in XML Schema 1.1 might be used for such test-assertion-like test cases but how? If you write a set of descriptions of tests using XML markup of some kind and define that markup using XML Schema 1.1 I reckon you could match every atomic statement of a requirement or the like in a spec to a test assertion for that requirement and put an element in the markup to report on the testing of the test assertion and define that element in the XML Schema. If the XML Schema is written using version 1.1 then you can put an assertion into the definition of the element which when executed as an executable expression (with a Boolean result) against the element in the test report produces a yes/no answer (true/false answer, it being a 'Boolean', 'predicate' expression). </span><br />
<br />
<span style="font-family: Verdana;">That might be one way to do it which results in a layer of yes/no answers which can be overlaid on the report to show whether test results are conforming to the test assertions or not. Another way works if the target is itself an XML document but here it gets more challenging. The assertions are run against the XML target but how do they get stored in the XML Schema, I wonder? The test assertions might be themselves documented using markup such as OASIS's Test Assertion Guidelines Technical Committee's (in progress) Test Assertion Markup Language (which I helped write up). Then we are left with the test cases which I wonder whether they can somehow be put into the form of a W3C XML Scheme 1.1 schema. They could be put into the form of a Test Assertion Markup Language XPath profile document and executed that way against the target XML using a tool like the Google Code project's Tamelizer (by Fujitsu America, based on previous work with WS-I) but that doesn't use XML Schema 1.1, it uses XSLT 2.0, which is cool. (Schematron is a similar alternative too which also uses XSLTXPath used by XML Schema 1.1 and the above alternatives) to some kind of schema but it isn't obvious how to do so. I think I'd need a report-like XML structure with one element for each test case and for each element (or element's 'type', an XML Schema thing) a schema definition where I can insert the XPath assertion expression. That doesn't work. I don't want to run the schema against the XML structure, I want to run the assertions in it against the target XML. No good. The target XML might have its own schema. What I have to do is create a schema for the target and put my assertions there. But it constrains the way I define my schema, perhaps not the way I want to do it for the type of XML document I am testing. Still it is an option. Another is to write tests and report on them in a test report document and define the test report document's XML using the schema where I put the assertions. That means two steps and is the same as the first option I looked at above which need not be limited to XML targets (or even software targets, similarly with Tamelizer).</span><br />
<br />
<span style="font-family: Verdana;">Right so I might decide I can indeed use XML Schema 1.1 to define the target and put my assertions into the individual elements' definitions. I'd probably want a 'global' element definition for each element which always has the same test assertion(s) applying to it wherever it occurs. If the test assertions depend on where the element occurs then I might have to have local elements defined so they can have a set of test assertions applied to them depending on their context (where they occur in the document). This messes with my design a bit but seems to be part and parcel of this technique. All-in-all I need my assertions to map to the test assertions and the test assertions to map to the 'normative' statements in the spec for that type of document. OK, fine. It means to use this approach I have to base my schema design not just on the document's XML structure and processes intended for the document which might impose requirements on the schema design but also I base the schema design partly on the spec design too insomuch as that dictate the test assertions and their granularity. I might then have a mix of global element definitions and local element definitions but I would foresee possible problems if an element has some assertions relating to it as a target which depend on its context in the document and some which don't. In these cases the local, context-dependant requirements (and their test assertions) trump the global, context-independent ones and the element might just have to be defined with one or more local definitions in the schema.</span><br />
<br />
<span style="font-family: Verdana;">I conclude I'm fairly comfortable with the use of W3X XML Schema 1.1 for associating test assertions with XML documents and even with other targets for testing but it might be limited to applying a kind of truth table of yes and no test reports as a layer over the top of a more general test report for tests made some way other than with the assertion expressions themselves and this goes along similar lines to those used in tools like Tamelizer. To go further and make the schema double as the set of test cases (the test suite or part of it) requires, I think, that the target be an XML document which is itself defined using a schema under the control of the test assertion and / or test case author(s). Cool. </span>Stephen D Greenhttp://www.blogger.com/profile/11733910745267236574noreply@blogger.com0tag:blogger.com,1999:blog-1907598603595683431.post-88917500016869782702011-03-09T01:31:00.001-08:002011-03-10T05:38:40.674-08:00XML Special Character Gotchas<div class="Section1">
<div class="MsoNormal">
<span lang="EN-US">You know you've got past the beginner tutorial and you're doing the real thing with XML when you start to get encoding and special character issues. Here's what I mean. You get some code which takes some XML, perhaps produced by a web page, and passes it to an XML parser. Now, just like other formats like JSON and HTML, XML requires that certain 'special characters' be 'escaped' (replaced with sequences like '&amp;' which is the escape sequence for an ampersand character). So if your XML contains some of these characters then they have to be replaced or the XML is not right. This introduces a catch-22 gotcha for XML parsers (at least it does for the ubiquitous one I use and probably does for others too) in that you might need to parse the XML as a first step in replacing the special characters (or how can you tell the character is in element or attribute content rather than a comment, namespace string or element or attribute name, say?). Trying to parse XML containing these characters might cause the parser to throw an error. That, apparently, is because the XML standard specs seem to give the impression this is the correct behavior of an XML parser (though I'm told on authority that this isn't strictly what the specs intended). </span><br />
<br />
<span lang="EN-US">The way I had to solve this with my C# code and .NET XML parser was to try parsing the XML, then catch any 'XML exception' errors, then do some things with the exception message and parsed data which aren't exactly advisable (since you don't know what state the parser data will be in after the exception) but seem to be unavoidable for an ordinary developer like myself. I have to get the offending bit of data from the parser using the line number and line position of the error from the error / exception message. Then do some intelligent replacing of a special character while avoiding replacing special characters which are part of the escape sequence of an already replaced special character! Phew! I just wish the parser would do all this for me but there are so few XML parsers available to me in my development environment (two I think) and neither handle this scenario the way I'd like, it seems.</span><br />
<br />
<span lang="EN-US">Here's a rendition of a general function to do all this in C# with .NET 2 or 3. I'm not necessarily proficient enough to say anyone else should use this code - it probably needs some better error handling and optimization, besides the fact it makes some assumptions which might not always be safe. It show the kind of issues a developer may face when parsing XML. Actually, I couldn't find much code anywhere on the Internet to handle this issue. In fact found very little written about this issue at all apart from an aged link here which helped as a starting point <a href="http://support.microsoft.com/kb/316063"><span style="color: purple;">http://support.microsoft.com/kb/316063</span></a> :</span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">public</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> <span style="color: blue;">static</span> <span style="color: blue;">string</span> EscapeXmlSpecialCharacters(<span style="color: blue;">string</span> XmlString)</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">{</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">string</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> resultString = <span style="color: #a31515;">""</span>;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 7.5pt;">//Create and load the XML document.</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: #2b91af; font-family: "Courier New"; font-size: 7.5pt;">XmlDocument</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> doc = <span style="color: blue;">new</span> <span style="color: #2b91af;">XmlDocument</span>();</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">try</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">{</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">doc.LoadXml(XmlString);</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">resultString = XmlString;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">}</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">catch</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> (<span style="color: #2b91af;">XmlException</span> ex)</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">{</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: #2b91af; font-family: "Courier New"; font-size: 7.5pt;">StringReader</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> str = <span style="color: blue;">new</span> <span style="color: #2b91af;">StringReader</span>(XmlString);</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: #2b91af; font-family: "Courier New"; font-size: 7.5pt;">StringWriter</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> stw = <span style="color: blue;">new</span> <span style="color: #2b91af;">StringWriter</span>(<span style="color: blue;">new</span> <span style="color: #2b91af;">StringBuilder</span>(resultString));</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">string</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> output = <span style="color: #a31515;">""</span>;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">long</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> i = 0;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">string</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> strline = <span style="color: #a31515;">""</span>;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">long</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> linenumber = (<span style="color: blue;">int</span>)ex.LineNumber;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">long</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> lineposition = (<span style="color: blue;">int</span>)ex.LinePosition;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">while</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> (i < linenumber - 1)</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">{</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">strline = str.ReadLine();</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">stw.WriteLine(strline);</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">i = i + 1;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">}</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">strline = str.ReadLine();</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">string</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> strOffendingCharacter = strline.ToString().Substring((<span style="color: blue;">int</span>)lineposition - 2, 1);</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">string</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> strOffendingCharacterAndFollowing5 = strline.ToString().Substring((<span style="color: blue;">int</span>)lineposition - 2, 5);</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">switch</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> (strOffendingCharacter)</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">{</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">case</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> <span style="color: #a31515;">"<"</span>:</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">strline = strline.Substring(0, (<span style="color: blue;">int</span>)lineposition - 2) + <span style="color: #a31515;">"&lt;"</span> + strline.Substring((<span style="color: blue;">int</span>)lineposition - 1);</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">break</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">case</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> <span style="color: #a31515;">"&"</span>:</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: green; font-family: "Courier New"; font-size: 7.5pt;">// ensure we are not replacing the ampersand in an already escaped special character (&lt;, &gt;, &apos;, &quot; or &amp;)</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">switch</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> (strOffendingCharacterAndFollowing5.Substring(1, 3))</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">{</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">case</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> <span style="color: #a31515;">"lt;"</span>:</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">break</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">case</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> <span style="color: #a31515;">"gt;"</span>:</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">break</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">default</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">:</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">switch</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> (strOffendingCharacterAndFollowing5.Substring(1, 4))</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">{</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">case</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> <span style="color: #a31515;">"amp;"</span>:</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">break</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">default</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">:</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">switch</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> (strOffendingCharacterAndFollowing5)</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">{</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">case</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> <span style="color: #a31515;">"apos;"</span>:</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">break</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">case</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> <span style="color: #a31515;">"quot;"</span>:</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">break</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">default</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">:</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">strline = strline.Substring(0, (<span style="color: blue;">int</span>)lineposition - 2) + <span style="color: #a31515;">"&amp;"</span> + strline.Substring((<span style="color: blue;">int</span>)lineposition - 1);</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">break</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">}</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">break</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">} </span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">break</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">}</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">break</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">}</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">stw.WriteLine(strline);</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">strline = str.ReadToEnd();</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">stw.WriteLine(strline);</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">output = stw.ToString();</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">str.Close();</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">str = <span style="color: blue;">null</span>;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">stw.Flush();</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">stw.Close();</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">stw = <span style="color: blue;">null</span>;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">resultString = EscapeXmlSpecialCharacters(output);</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">}</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="color: blue; font-family: "Courier New"; font-size: 7.5pt;">return</span><span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;"> resultString;</span></div>
<div class="MsoNoSpacing">
<span lang="EN-US" style="font-family: "Courier New"; font-size: 7.5pt;">}</span></div>
<div class="MsoNoSpacing">
<br /></div>
<div class="MsoNoSpacing">
Then you can put in a step between receiving some XML from, say, a web control like a grid and sending that XML as a string to an XML parser like XmlReader so that you can read the string into a .NET dataset, say. No idea what the equivalent issues and solution are like in Java, sorry. If you write your own XML parser though this is one of the issues you will have to bear in mind and handle, along with similar XML-related issues like handling the illegal characters and characters which are not encoded with the encoding declared in the XML declaration (usually UTF-8). Targeting such a parser at supporting just MicroXML, say (see earlier blogs on MicroXML and MicroXSD) might help to keep these issues to something manageable for people writing their own parsers; we'll see perhaps.</div>
<div class="MsoNormal">
<br /></div>
</div>Stephen D Greenhttp://www.blogger.com/profile/11733910745267236574noreply@blogger.com3tag:blogger.com,1999:blog-1907598603595683431.post-3911657819809085742011-03-08T02:11:00.000-08:002011-03-08T02:11:12.744-08:00MicroXML<h1>
<span lang="EN-US" style="font-variant: normal !important; text-transform: uppercase;">Using MicroXML</span></h1>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Some tend to think XML is rather complex and mysterious yet all it is, fundamentally, is a set of building blocks for text: element tags, element content, attribute names, attribute values and the structure (the way the building blocks are arranged). Let’s look at these in turn, while limiting our focus to the simplification of XML which is called MicroXML. In the process we also need to address some special concerns, such as some considerations that have to be given to certain characters and how to denote a comment as being distinct from the XML content. [MicroXML is a subset profile of XML developed by James Clark and published in a blogspot by James at <a href="http://blog.jclark.com/2010/12/more-on-microxml.html">http://blog.jclark.com/2010/12/more-on-microxml.html</a> .]</span></div>
<div class="MsoNormal">
<br /></div>
<h3>
<span lang="EN-US" style="font-variant: normal !important; text-transform: uppercase;">Element Tags</span></h3>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">The simplest and most obvious part of XML is the tag. Tags surround text, sometimes surrounding other tags and sometimes including within the tag other structures called attributes. Tags are sometimes in pairs and sometimes alone. When they are in pairs then there is a leading tag or ‘start tag’ and a trailing tag or ‘end tag’ and usually some text between them. If there is a start tag and end tag without any text between them then it can also be written in an alternative, equivalent form called an empty tag which is the one time when the tag has no pair. </span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">In computer programming, the simplest kinds of examples are often called ‘Hello World’ examples because a very famous book once introduced readers to the early programming language called ‘C’ with an example that output a simple string of characters saying just ‘Hello World’. Using MicroXML we might have an equivalent simple example like this:</span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <Hello>World</Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">This is called an element. This element has a start tag </span><span lang="EN-US" style="font-family: "Courier New";"><Hello></span><span lang="EN-US">, an end tag </span><span lang="EN-US" style="font-family: "Courier New";"></Hello></span><span lang="EN-US"> and between the tags some text reading ‘</span><span lang="EN-US" style="font-family: "Courier New";">World</span><span lang="EN-US">’. Simple! Start tags have an opening angle bracket or ‘less-than’ sign </span><span lang="EN-US" style="font-family: "Courier New";"><</span><span lang="EN-US"> followed by the name given to the element followed by the closing bracket or ‘greater than’ sign </span><span lang="EN-US" style="font-family: "Courier New";">></span><span lang="EN-US">. There is no white space unless the start tag contains one or more attributes, as we’ll see later. White space is that set of characters in text which do not have any visible shape like spaces, tabs, new-lines, etc. The name of the element (in this case ‘Hello’) is not allowed to contain any white space. Neither is an element allowed to start with a digit but it can contain any number of digits after the first character. A formal definition of MicroXML states that the first character of a name (element or attribute name) cannot be a digit but can be an alpha character or underscore (or some other more obscure characters which are listed by their ASCII codes see formal definition of MicroXML here <a href="http://blog.jclark.com/2010/12/more-on-microxml.html"><span style="color: purple;">http://blog.jclark.com/2010/12/more-on-microxml.html</span></a> ). Other name charcters after the first do cannot include the underscore but can include digits, alpha characters and the two punctuation characters point (full stop) ‘.’ and hyphen (dash) ‘-’.</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">End tags start with an opening angle bracket or less-than sign ‘<’ followed by a forward slash ‘/’ then the same element name as the start tag used and finally the closing angle bracket or greater than sign ‘>’. So our example element:</span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <Hello>World</Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">is composed of:</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Start tag:</span><span lang="EN-US" style="font-family: "Courier New";"> <Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Content:</span><span lang="EN-US" style="font-family: "Courier New";"> World</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">End tag:</span><span lang="EN-US" style="font-family: "Courier New";"> </Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Then there is that special case of element tags which stand alone without being in a pair. These tags are an alternative way to show a special kind of element; one that does not have any content. The ‘Hello’ in our example above, if the text ‘World’ were removed, could be written like this: </span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <Hello></Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">but it could also be written like this with just one special tag: </span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <Hello/></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Elements can contain another kind of structure called an attribute. Attributes when added to an empty element can look like this: </span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <Hello from=”Mars” to=”World”/></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">The special tag for the empty element starts with the opening angle bracket, then comes the element name and then there can sometimes be white space, such as when the element has an attribute, but whether or not there is any white space it always closes with a backslash immediately followed by a closing angle bracket or greater-than sign. (There are some times when white space follows the element name even when there are no attributes but the reason is not important at this stage except to remember it is possible.)</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Note that when there are one or more attributes added to an element the attributes and their values (they always have values in MicroXML) always sit between the element name and the closing angle bracket of the start tag, or when the tag is the standalone empty element tag, between the element name and the backslash, i.e. like the example above, or like this: </span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <Hello from=”Mars”>World</Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Also, the quotes around the attribute value can be a pair of double quotes or a pair of single quotes.</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<h3>
<span lang="EN-US" style="font-variant: normal !important; text-transform: uppercase;">Element Content and Mixed Content</span></h3>
<div class="MsoNormal">
<span lang="EN-US"> </span><span lang="EN-US" style="font-variant: normal !important; text-transform: uppercase;"> </span></div>
<div class="MsoNormal">
<span lang="EN-US">We’ve seen that an element can contain text but it can also contain other elements, or both. When it contains text alone then the text is simply everything between the start and end tag. In the example above that means just ‘World’. When it contains other elements then the other elements sit between the start and end tags but there may or may not be white space between the end of the first element’s start tag and the next element’s start tag. When the element contains both elements and text then it is called mixed content and the text and other elements along with any white space still sit between the first element’s start and end tags. So you can have content like this:</span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <Hello><From>Mars</From><To>World</To></Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">or with white space like this:</span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <Hello> <From>Mars</From> <To></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";">World</To></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"></Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">or with mixed content like this:</span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <Hello>From Mars <To>World</To></Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Both white space and mixed content together makes the XML look less recognizable as XML, but it is still allowed, like this:</span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";">.. <Hello>From </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";">Mars </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><To></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";">World</To></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"></Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<h3>
<span lang="EN-US" style="font-variant: normal !important; text-transform: uppercase;">Attribute Names and Values</span></h3>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">The attribute consists of a name and a textual value. The name and value together are placed in an element start tag or empty tag (not end tag) between the element name and the closing angle bracket. The name goes first followed, always, by an equals sign (with or without any white space between) followed (again, with or without any white space) by the attribute’s textual value surrounded by either single or double quotes like this: </span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <Hello from=’Mars’>World</Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">or like this</span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <Hello from = ”Mars” to=”World” /> </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">or like this</span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <Hello from= ”Mars” via=”My website”>World</Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Note the various combinations of characters allowed such as white spaces and single or double quotes. Note too that if an attribute value were ever to contain an element it would not normally be recognized as an element but would normally be treated as just text. (Of course, it would be possible to instruct some computational process to extract the value of the attribute and treat it as XML in its own right but normally the value of the attribute is treated as just textual content.) </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">The attribute names are limited in their allowed characters just as element names are: no leading digits, only certain punctuation characters allowed, etc. Note also that with an attribute name in MicroXML there is a special case of names beginning ‘xml:’ which are reserved names for special purposes specified in the XML Standards. Normally the colon is not allowed in an attribute or element name in MicroXML (because it has a special function given it in parts of the XML specifications not included in MicroXML but which would affect the way MicroXML was handled by tools used to handle XML in general). The ‘xml:’ prefix is allowed in attribute names in MicroXML, however, mainly to allow a special feature to be used which is an ‘xml:id’ special attribute (out of scope here).</span><span lang="EN-US"> </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<h3>
<span lang="EN-US" style="font-variant: normal !important; text-transform: uppercase;">Special and Illegal Characters </span></h3>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">We have already seen that some characters in element and attribute names are illegal in MicroXML (and some of these are so in XML in general). In addition, to help processors interpret the XML properly and reliably there are some characters which are not allowed in the content. That might seem alarming and so it should: What, you might think, if there are such characters in text we wish to include between tags or in attribute values? What do we do with these characters? The answer is that they have to be replaced with what can be called ‘escape’ strings. This is one big drawback with using MicroXML or XML in general. The reason is clear when you think of what would happen if the text content of an element had a less-than sign in it: It could look very much like an end tag and in some cases might be indistinguishable from one, for example:</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: "Courier New";"><MathStatement>one < two</MathStatement></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">is potentially confusing but even more so is:</span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><two>one<two</two></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">Attributes are not exempt and the following is not allowed:</span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><two one=”<two”</one></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">The special characters this applies to are </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Ampersand &</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Less-than <</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Greater-than > </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Double-quote "</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Single-quote (apostrophe) '</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">The reason the ampersand ‘&’ is a special character too becomes apparent when we consider what we have to do with these characters to replace them. It is called ‘escaping’ and it consists of replacing these characters with a special sequence of characters which are as follows:</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Ampersand &amp; </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Less-than &lt; </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Greater-than &gt; </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Double-quote &quot; </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Single-quote (apostrophe) &#39; or &apos;</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">The escape strings themselves can start with an apostrophe so this too is a special character. </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Now all this poses problems which may have to be solved for people producing the XML, either through text editing or computer programming. You have to not just replace the special characters with their escape sequences but you have to ensure that when doing so you distinguish what is an apostrophe that is part of the text and what is an apostrophe at the start of an escape string (else you might end up producing something like &apos;apos; and eventually &apos;apos;apos;apos; or worse). Then you have to think about how to read the XML in any computer code, when to escape those characters, when to replace them back for humans to read, etc. It can all get complex but the same happens with web browsers which have to do this kind of thing for the language of the Web, HTML, too.</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Other characters are said to be ‘illegal’ in MicroXML because all the content and the tags and attribute names and values have to be written in the character set of the encoding known as UTF-8 so any characters not a found in this encoding system’s character set have to be replaced at some point too. This might best be achieved by controlling which characters are actually added to the MicroXML rather than by escaping them (because escaping such characters introduces some extra complications out of scope here).</span><span lang="EN-US"> </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">It has not been mentioned until now but the start of a document written in MicroXML should be the UTF-8 character encoding declaration along with the general XML (version 1.0) declaration:</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><?xml version="1.0" encoding="UTF-8"?></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";">… (</span><span lang="EN-US">rest of the MicroXML follows on).</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">This, for the Hello World example, would look like the following:</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><?xml version="1.0" encoding="UTF-8"?></span></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: "Courier New";"><Hello from=’Mars’>World</Hello></span></div>
<h3>
<span lang="EN-US" style="font-variant: normal !important; text-transform: uppercase;"> </span></h3>
<h3>
<span lang="EN-US" style="font-variant: normal !important; text-transform: uppercase;">Comments</span></h3>
<h3>
<span lang="EN-US" style="font-variant: normal !important; text-transform: uppercase;"> </span></h3>
<div class="MsoNormal">
<span lang="EN-US">To allow ignorable comment text to be interspersed with the MicroXML comments are separated from the rest of the XML by the special sequence of characters: left angle-bracket (less-than sign) followed without white space by an exclamation mark and, again no white space, two consecutive hyphens (dashes) then the comment then two consecutive hyphens and (without intervening white space) a right angle-bracket (greater-than sign). </span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US" style="font-family: "Courier New";"><!-- then textual comment here then --> </span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">This looks like the following when the comment is embedded in some XML:</span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><Hello>From </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><!-- this is a comment --> </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";">Mars </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><To></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";">World</To></Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">This says that the comment is not to be regarded as actual content and it can be ignored. The comment’s text does not need to be escaped. Comments cannot be nested in MicroXML. One comment has to be ended before the other begins. </span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">This is allowed:</span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><Hello>From </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><!-- this is a comment --> </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><!-- this is another comment --> </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";">Mars </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><To></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";">World</To></Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-US">but not this: </span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><Hello>From </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><!-- this is a comment </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><!-- this is an illegally nested comment --> --></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";">Mars </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><To></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";">World</To></Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<h3>
<span lang="EN-US" style="font-variant: normal !important; text-transform: uppercase;">Structure</span></h3>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">There are very many ways the above building blocks of MicroXML (and XML in general) can all be combined to form simple or complex structures but special note needs to be given to the hierarchical or tree-like nature of the structure due to there always being one and only one top level element. This is because there is a distinction made between a self-contained piece of XML and other partial pieces of XML. The first can be called an ‘instance’ and the latter can be called ‘fragments’. An ‘instance’ has special status. This is an instance:</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><Hello><From>Mars</From><To>World</To></Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">whereas the following is not an instance but is a fragment:</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><From>Mars</From><To>World</To></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">That is because the first example is wrapped in a single element and the latter has two elements without any single element wrapper. </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Then again the following is not even a fragment because as it stands it would not be valid MicroXML because it has a missing tag at the start and an incomplete one at the end:</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";">Mars</From><To>World</To</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">To be perfect the instance example would be more complete as an instance (or XML document) if it had its declaration: </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><?xml version="1.0" encoding="UTF-8"?></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><Hello><From>Mars</From><To>World</To></Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Then a common practice is to add some indentation to make it easier to see that it has a structure because that structure sometimes expresses some of the meaning of the XML.</span><span lang="EN-US"> </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><?xml version="1.0" encoding="UTF-8"?></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <From>Mars</From></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <To>World</To></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"></Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">The indentation is added using white space but this is not essential. It does illustrate the fact that the instance having a single wrapper around the outside, each element possibly wrapping other elements but attributes wrapping nothing gives the XML a tree-like or hierarchical logical structure.</span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">The tree-like structure is described sometimes using language which alludes to a family tree (as we do later in the discussion of MicroXSD) where one element containing another element is said to be the parent of the second element (and XML elements can only have the one ‘parent’) and the second is said to be one of the child elements of the first. Two child elements sharing the same parent are often metaphorically called ‘siblings’. </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<h2>
<span lang="EN-US" style="font-variant: normal !important; text-transform: uppercase;">The Use of a Namespace</span></h2>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">There are times when there may be several instances of XML in one file or, say with mixed content, when various instances are somehow interspersed. To distinguish one instance from another we can assign a special name to each instance via a special attribute called the namespace attribute. The special name is called a namespace. We will see more about this in the section on MicroXSD, but the way that a namespace name is composed is a matter of discretion and might involve adhering to some sort of namespace naming scheme (such as a schemes involving URIs or domain names). The namespaces in MicroXML are limited compared to full, standard XML 1.0 and are assigned using the attribute ‘xmlns’ like this: </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><?xml version="1.0" encoding="UTF-8"?></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><Hello xmlns="somenamespace"></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <From>Mars</From></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <To>World</To></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"></Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">Any string is allowed as the value of the attribute. It is worth bearing in mind that this is a key area of simplification in the MicroXML profile of XML; full, standard XML is greatly complicated by the allowance of any number of namespaces in an instance with each namespace being assigned to respective elements and attributes using special prefixes in the element and attribute names. For MicroXML this is eliminated for greater simplicity. This does mean that we have to keep the namespaces separated more so that we are limited in how we combine elements from different namespaces: Essentially all elements from one namespace have to be completed (all end tags closed) before another begins. For example we might have a file whose top element has no namespace but within this element are two parent elements for two parts of the rest of the instance each with a different namespace: </span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><?xml version="1.0" encoding="UTF-8"?></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"><Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <From xmlns="somenamespace1">Mars</From></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"> <To xmlns="somenamespace2">World</To></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US" style="font-family: "Courier New";"></Hello></span></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">This is allowed because the two namespaces do not overlap. Every element within an element having a particular namespace has that same namespace in MicroXML.</span></div>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<br /></div>
<h2>
<span lang="EN-US" style="font-variant: normal !important; text-transform: uppercase;">The Use of a Schema</span></h2>
<div class="MsoNormal">
<br /></div>
<div align="left" class="MsoNormal" style="text-align: left;">
<span lang="EN-US">It might clearly help the handling of the XML or of various parts of it if we pay attention to the design of its structure and seek to document it in a way which humans or even software can read. The structure with its element and attribute names can be defined outside of the XML using some techniques designed especially for XML which can be used with MicroXML too. This also provides a designer of the XML structure with the opportunity to add some further information to describe and possibly constrain the XML, such as by associating a type with the content of a particular element or attribute. One such technique is to associate a schema with the XML. Such a schema can be written using MicroXSD, as seen in the previous blog [ <a href="http://stephengreenxml.blogspot.com/2011/02/microxsd.html">http://stephengreenxml.blogspot.com/2011/02/microxsd.html</a> ] which is a subset profile of W3C XML Schema. MicroXSD was developed by this blog's author especially for use with MicroXML.</span></div>
<div class="MsoNormal">
<br /></div>Stephen D Greenhttp://www.blogger.com/profile/11733910745267236574noreply@blogger.com1tag:blogger.com,1999:blog-1907598603595683431.post-76945673423184292982011-03-03T14:03:00.000-08:002011-03-08T02:13:30.493-08:00MicroXSD<h1 class="western" lang="en-US">
Introduction </h1>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<h2 class="western" lang="en-US">
MicroXML</h2>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br />
Toward the end of 2010 XML was getting a bit of a rethink in the XML community. First people talked about what for some had been unthinkable in its first decade, an ‘XML 2.0’. That may be on hold; perhaps just as well. For some it has been a major selling point that no 2.0 was planned when XML was created, so archived XML documents might still be readable (parseable) with software decades from now and printed XML still comprehensible decades after that. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
What seems more likely is that those who find XML too onerous to use for their purposes will get as much as they need in the form of a predefined subset of XML. Efforts to define possible 80:20 subsets (80 percent of what you need with 20 percent of the complexity) have begun afresh of late, with the first major contender being called 'MicroXML'. The main discussion of MicroXML happened on the XML-Dev public mailing list in December 2010. [MicroXML is a subset profile of XML developed by James Clark and published in a blogspot by James at <a href="http://blog.jclark.com/2010/12/more-on-microxml.html"><span style="color: #888888;">http://blog.jclark.com/2010/12/more-on-microxml.html</span></a> . I blog on its use in the next blog.]<br />
<br /></div>
<h2 class="western" lang="en-US">
MicroXSD</h2>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
Along with MicroXML there was discussion of the possibility of a simplified subset of languages used for defining structural constraints on XML instances. The standard full version of the main constraint language is called W3C XML Schema but often an alias is used for this in the acronym XSD (XML Schema Definition). MicroXSD is such a subset. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
MicroXSD eliminates all but the essentials and only allows 'local' element definitions with unnamed complex and simple types. This makes the 'schema' look similar to the XML it defines. Some will find that an improvement because many acknowledge that the average schema written with XSD-proper is somewhat incomprehensible, even to the well-trained eye. MicroXML, as defined in late 2010 does not allow multiple namespaces (namespaces add some of the most atrocious complexities to standard XML) so MicroXSD need only support zero or one namespace, meaning no imports. Having an easier way to define (and understand) the constraints to be applied to a vocabulary written in MicroXML might allow more people to find it within their means to produce and use XML and write software supporting this subset of it. </div>
<h1 class="western" lang="en-US">
Using MicroXSD</h1>
<h2 class="western" lang="en-US">
Writing the simplest schema</h2>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
A Schema written in MicroXSD inherits the semantics of a schema written in standard W3C XML Schema 1.0 (often known by the acronym XSD) except that not every element and attribute in W3C XML Schema is allowed in MicroXSD: It is a subset. (Note again that MicroXSD is particularly but not solely targeted for defining XML instances written in the subset of XML called 'MicroXML' as mentioned in the introduction.) </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
A schema is a file or string (or the like) of XML markup which defines and constrains the structural aspects of another instance or fragment of XML. It cannot express every aspect of the constraints which might be required for some uses of XML but it is often the first choice to use for the definition since it supports some of the most common requirements and is quite ubiquitous, well known and well supported in XML-related software. Once a schema is defined there are other ways to fill the gaps, such as with prose specification statements, assertions or test assertions. The MicroXSD subset cannot support all typical use cases (such as cases where there is much reuse of XML syntax, as with XHTML) but where it can be used it offers ease of interpretation of the schema by a human reader plus reduced complexity when writing software to execute validation of the schema against a target instance. Often the latter is necessary as a prerequisite to further processing of XML in software.</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br /></div>
<h3 class="western" lang="en-US">
The 'schema' Element: <schema> </h3>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
Every conforming MicroXSD schema starts with the 'scheme' element as its outermost (top level) element. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
An example: </div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><schema xmlns="http://www.w3.org/2001/XMLSchema" version="123" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="somenamespace"> </span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br />
<br />
Lets pull this apart and see how it works. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><schema></span> is the top level element in a schema. It wraps all the other schema elements in this way</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><schema ...> ...</span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"></schema> </span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br />
<br />
Attributes of the 'scheme' element are as follows.</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;">xmlns="http://www.w3.org/2001/XMLSchema"</span> : This attribute with this name and value is mandatory in a schema top level element. It provides the schema with a namespace. All elements between <schema> and </schema> share this namespace. This namespace is the namespace of the language used to write the schema, NOT the namespace of the XML constrained by the schema. For the latter, in MicroXSD, the 'targetNamespace' attribute is used (see below). </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;">version="123"</span>: This attribute gives the schema a version number (sometimes characters other than numbers are used too such as '123.1.0' or even 'foo-draft-1'). </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;">attributeFormDefault="unqualified" elementFormDefault="qualified"</span> : Included for compatibility with existing software processing W3C XML Schema and with the XML Schema standard, these attributes and the values shown are necessary to clarify how to interpret the namespaces of attributes and elements in the instance of XML constrained by the schema. They are fixed with these values in MicroXSD. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br /></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;">targetNamespace="somenamespace"</span> : This attribute defines which namespace is to be assigned to an XML instance constrained by the schema. It is optional and if missing the namespace is assumed to be empty. Typically namespaces follow some scheme (scheme, not schema) which helps, for example, to associate the namespace with some provenance. One such scheme is to use the authors' URL or domain name perhaps together with an identifier of some find. Any string is allowed though. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
In a MicroXSD schema no other attributes should be present in this top level 'scheme' element. The only element allowed immediately below (within) this scheme element in a MicroXSD schema is the 'element' element (the element called 'element'!). (Other possibilities acceptable in W3C XML Schema are not supported with the MicroXSD subset profile.) </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<h3 class="western" lang="en-US">
The Topmost 'element' Element: <element> </h3>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br />
<br />
The element called 'element' (beware confusion!) is found just below the 'scheme' element but can also be nested further down within itself: 'element' elements can contain other 'element' elements (albeit indirectly). An example of its use when it is directly below the 'scheme', top level element is </div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><element name="Hello"> ... </element> </span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;">name="Hello"</span>: This 'name' attribute is the only attribute allowed in 'element' in MicroXSD for the topmost 'element' (which is directly below the top level 'scheme' element). It defines the name of the top level element in the constrained XML instance. It can have as its value any valid XML name as specified by the XML 1.0 Standard and in MicroXML: Starting with an alpha (ASCII) or underscore ('_') character, not including any spaces, but with numbers and some punctuation characters (such as the point '.' or underscore '_') allowed after the first character.</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
When the 'element' element occurs lower down in the schema structure it can also take the attributes 'minOccurs' and 'maxOccurs' and these will be looked at later. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br />
The only child element allowed in MicroXSD for 'element' element is called 'complexType'. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br />
Example of a topmost element with its complex type: </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><element name="Hello"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <complexType mixed="true"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> ... </span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
Wherever the 'complexType' element is used in MicroXSD its syntax is the same. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<h3 class="western" lang="en-US">
Simplest use of the 'complexType' Element </h3>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br />
Here is a so-called 'Hello World' example:</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
For the simple XML</div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><Hello>World</Hello></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
we can use MicroXSD to write the schema </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><schema xmlns="http://www.w3.org/2001/XMLSchema" version="0.1" attributeFormDefault="unqualified" elementFormDefault="qualified"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <element name="Hello"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <simpleContent></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <extension base="string"/></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </simpleContent></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </element></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"></schema> </span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
Here the complexType element has one child which is 'simpleContent' (other child elements are allowed in MicroXSD and these will be looked at later on). That child 'simpleContent' itself has one required child element (the only allowed child element of 'simpleContent' in MicroXSD) which is called 'extension' which has a single, required attribute called 'base'. The 'base' attribute has a value which defines the datatype of the content (in the above example, the datatype of the content of the 'Hello' element). Allowed values for 'base' are string, decimal, integer, date, dateTime, boolean and base64Binary. These are some of the more commonly used standard datatypes for W3C XML Schema.</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
The above schema allows the XML </div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><Hello>Reader</Hello> </span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
but does not allow </div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><Hello><Reader/></Hello></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
because the latter contains another element named 'Reader' rather than just some text data of type 'string'. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
The markup language, XML, allows both elements and attributes so in the next section we will look at how to add some attributes to this simple element.</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<h2 class="western" lang="en-US">
Adding attributes</h2>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
A very simple 'Hello World' example XML and a corresponding MicroXSD schema : </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><Hello>World</Hello></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
which may be constrained by MicroXSD schema</div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><schema xmlns="http://www.w3.org/2001/XMLSchema" version="0.1" attributeFormDefault="unqualified" elementFormDefault="qualified"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <element name="Hello"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <simpleContent></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <extension base="string"/></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </simpleContent></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </element></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"></schema></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
XML can have attributes as well as elements so a Hello World example could be written: </div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><Greeting to=”World”>Hello</Greeting></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<h3 class="western" lang="en-US">
The 'attribute' Element: <attribute> </h3>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
The 'complexType' allows us to specify whether an element has child elements and whether it has attributes. When there are no child elements to be added to the instance element we use 'complexType' with a 'simpleContent' child and inside that we place a child of 'simpleContent' called 'extension'. In MicroXSD the element 'simpleContent' can only have this 'extension' element as a child element. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
So far we have defined the following</div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><Greeting>Hello</Greeting></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
and we need to add the attribute named 'to' to give us</div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><Greeting to=”World”>Hello</Greeting></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
We do this by adding 'attribute' elements as children of the 'extension' element. The 'extension' element in MicroXSD is limited to having the attribute 'base' (with values limited in MicroXSD to a range of commonly used datatypes: string, decimal, integer, date, dateTime, boolean and base64Binary) and the child element 'attribute'. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><schema xmlns="http://www.w3.org/2001/XMLSchema" version="0.1" attributeFormDefault="unqualified" elementFormDefault="qualified"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <element name="Greeting"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <simpleContent></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <extension base="string"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <attribute name="to"/></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <extension></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </simpleContent></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </element></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"></schema></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
To show that the attribute itself has content of a particular datatype we can use the element 'simpleType'. With MicroXSD this is the one way to do it. With full W3C XML Schema there is an alternative way which is to use a 'type' attribute of the 'attribute' element but that is not included in MicroXSD. Likewise in full W3C XML Schema there are several ways to assign a datatype to a simple content element but only one applies in MicroXSD, as shown above.</div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><schema xmlns="http://www.w3.org/2001/XMLSchema" version="0.1" attributeFormDefault="unqualified" elementFormDefault="qualified"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <element name="Greeting"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <simpleContent></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <extension base="string"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <attribute name="to"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <simpleType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <restriction base="string"/></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </simpleType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </attribute></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </extension></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </simpleContent></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </element></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"></schema></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<h3 class="western" lang="en-US">
The 'simpleType' Element: <simpleType> </h3>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><simpleType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <restriction base="string"/></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"></simpleType></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
In MicroXSD the element called 'simpleType' has only one child element called 'restriction' and no attributes. The 'restriction' element has only one attribute in MicroXSD named 'base' which has the same function and list of values as the 'base' attribute of the 'extension' element described above. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
Of course there can be more than one attribute for an element, though only one with any particular name (multiple attributes with the same name on the same element are not allowed). We could add another attribute to the example schema with the name 'from' like this: </div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><schema xmlns="http://www.w3.org/2001/XMLSchema" version="0.1" attributeFormDefault="unqualified" elementFormDefault="qualified"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <element name="Greeting"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <simpleContent></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <extension base="string"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <attribute name="to"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <simpleType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <restriction base="string"/></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </simpleType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </attribute></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <attribute name="from"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <simpleType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <restriction base="string"/></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </simpleType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </attribute></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </extension></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </simpleContent></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </element></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"></schema></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br /></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
This allows the further attribute 'to' to be added to the XML example: </div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><Greeting to=”World” from=”Mars”>Hello</Greeting></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br />
<br />
The 'attribute' element (confusing language isn't it!) in MicroXSD can have just the one attribute 'name'. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
For example:</div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><attribute name="to">...</attribute></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
The 'name' assigns a name to the attribute in the XML instance and like the name of an element, the name of an attribute has to conform to the naming standard in XML 1.0 which means no numbers as first character but apart from the first character both alphanumeric characters and some other characters such as point '.' and underscore '_' are allowed in any order. Because MicroXSD supports in particular a subset of XML called MicroXML (see introduction), the attributes' (and elements') names do not include the 'prefix' allowed in standard XML. This is to eliminate multiple namespaces. This decreases the complexity required in MicroXSD significantly. Note: It has been proposed that there should be support in MicroXML for prefixes for attribute names but as yet this has not been included in MicroXSD (version 2012). The term given to standard element and attribute names in XML without the prefix is 'NCName' (as distinct from the term for a name qualified with a prefix and associated namespace which is a 'QName' and QNames are not supported in this version of MicroXSD).</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<h2 class="western" lang="en-US">
Simply supporting complexity</h2>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br />
<br />
Here is a very simple example XML and corresponding MicroXSD schema : </div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><Greeting>Hello</Greeting></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
which may be constrained by MicroXSD schema</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br />
<br />
<span style="font-family: Courier New, monospace;"><schema xmlns="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <element name="Greeting"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <simpleContent></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <extension base="string"></extension></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </simpleContent></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </element></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"></schema></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
XML can have child elements within any given element so a Hello World example could be written: </div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><Greeting><Hello/></Greeting></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
This requires that we add an element, albeit an empty one, to the top level element. We do this by adding 'sequence' or 'choice' elements as children of the 'complexType' element (instead of the 'simpleContent' element). The 'sequence' element in MicroXSD is limited to having no attributes but a range of possible child elements. Likewise the 'choice' element. Each of these elements, 'sequence' and 'choice' allow us to specify that an element has child elements. The difference between them is clear from their names: 'sequence' is used when the sequence of the child elements is fixed whereas 'choice' is used to show that there is a choice between certain child elements or sets of child elements. When there is just one child element it is best to use 'sequence'. In our case we just want one child element so we will use 'sequence'. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br />
<br />
<span style="font-family: Courier New, monospace;"><schema xmlns="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <element name="Greeting"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <sequence></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <element name="Hello"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <complexType></complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </element></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </sequence></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </element></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"></schema></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br /></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
Here we have the unusual situation of having an empty complexType to show that the child element 'Hello' is empty. This complexType in MicroXSD, though, can be any complexType allowed by MicroXSD. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
Suppose we now wish to add several attributes to this child element, such as for an XML instance as follows: </div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><Greeting><Hello exclamation="true"/></Greeting></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
We add an attribute using the 'attribute' element but we place this element after any 'sequence' or 'choice' elements. We cannot use an 'attribute' element like this when using the 'simpleContent' we used before but if there is neither a 'simpleContent' nor a 'sequence' or 'choice' we can still add 'attribute' elements. To show that the attribute itself has content of a particular datatype we can use the element 'simpleType'. In the example we can make the datatype 'boolean' to match the use of values 'true' and 'false'. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br /></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><schema xmlns="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <element name="Greeting"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <sequence></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <element name="Hello"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <attribute name="exclamation"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <simpleType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <restriction base="boolean"/></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </simpleType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </attribute></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </element></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </sequence></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </element></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"></schema></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br /></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
With full W3C XML Schema there are other options available besides 'sequence' and 'choice' but with MicroXSD the only children of the 'complexType' are 'simpleContent', 'sequence', 'choice' and, when 'simpleContent' is not used, the 'attribute' element - to keep things simple. However, many structures with varying degrees of complexity are possible even with MicroXSD because the 'sequence' and 'choice' elements themselves can have nested 'sequence' and 'choice' elements. So the possible children of both 'sequence' and 'choice' in MicroXSD are 'element', 'sequence' (nested) and 'choice' (nested). Multiple 'sequence' or 'choice' elements are not allowed side-by-side though, they can only be nested. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
Here is a schema using MicroXSD with a little nesting </div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><schema xmlns="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <element name="Greeting"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <sequence></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <element name="Hello"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <choice></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <element name="World"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <complexType></complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </element></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <element name="Mars"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <complexType></complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </element></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </choice></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <attribute name="exclamation"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <simpleType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <restriction base="boolean"/></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </simpleType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </attribute></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </element></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </sequence></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </complexType></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </element></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"></schema></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
and this would result in allowing a XML instances a little more complex like this</div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><Greeting></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <Hello exclamation="true"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <World/></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </Hello></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"></Greeting></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
or this</div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"><Greeting></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <Hello exclamation="false"></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> <Mars/></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"> </Hello></span></div>
<div align="left" class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<span style="font-family: Courier New, monospace;"></Greeting></span></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
<br /></div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
This concludes the description of the more complex uses of MicroXSD. The degree of complexity is unlimited but other aspects are limited by both the fact we are using a subset of W3C XML Schema and the fact that W3C XML Schema is itself somewhat limited in its feature set and supplemented by other related technologies such as ISO Schematron, RelaxNG, Test Assertions, formatting tables, plain text specifications and programming code. However, the fact that MicroXSD is a subset of W3C XML Schema means that adhering to the MicroXSD metaschema in your schema design should ensure that tools conforming to W3C XML Schema can readily handle a MicroXSD schema. </div>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm; page-break-before: always;">
<br /></div>
<h1 class="western" lang="en-US">
The MicroXSD 'Metaschema' (the schema defining a MicroXSD schema)</h1>
<div class="western" lang="en-US" style="margin-bottom: 0.35cm;">
</div>
<span style="font-family: "Courier New", Courier, monospace;"><?xml version="1.0" encoding="UTF-8"?><br /><schema targetNamespace="<a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>" elementFormDefault="qualified" attributeFormDefault="unqualified" version="2012.02" xmlns="<a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>"><br /> <!-- MicroXSD 2012.02 --><br /> <!-- --><br /> <element name="schema"><br /> <complexType><br /> <sequence><br /> <element name="element" minOccurs="0"><br /> <complexType><br /> <sequence><br /> <element name="complexType" type="complexType_type"/><br /> </sequence><br /> <attribute name="name" type="NCName" use="required"/><br /> </complexType><br /> </element><br /> </sequence><br /> <attribute name="version" type="string" use="optional"/><br /> <attribute name="attributeFormDefault" use="required" fixed="unqualified"/><br /> <attribute name="elementFormDefault" use="required" fixed="qualified"/><br /> <attribute name="targetNamespace" type="string" use="optional"/><br /> </complexType><br /> </element><br /> <complexType name="element_type"><br /> <sequence><br /> <element name="complexType" type="complexType_type"/><br /> </sequence><br /> <attribute name="name" type="NCName" use="required"/><br /> <attribute name="minOccurs" use="optional"><br /> <simpleType><br /> <restriction base="string"><br /> <enumeration value="0"/><br /> <enumeration value="1"/><br /> </restriction><br /> </simpleType><br /> </attribute><br /> <attribute name="maxOccurs" use="optional"><br /> <simpleType><br /> <restriction base="string"><br /> <enumeration value="1"/><br /> <enumeration value="unbounded"/><br /> </restriction><br /> </simpleType><br /> </attribute><br /> </complexType><br /> <simpleType name="base_type"><br /> <restriction base="string"><br /> <enumeration value="string"/><br /> <enumeration value="decimal"/><br /> <enumeration value="integer"/><br /> <enumeration value="date"/><br /> <enumeration value="dateTime"/><br /> <enumeration value="boolean"/><br /> <enumeration value="base64Binary"/><br /> </restriction><br /> </simpleType><br /> <group name="element_sequence_choice"><br /> <choice><br /> <element name="element" type="element_type"/><br /> <group ref="sequence_choice"/><br /> </choice><br /> </group><br /> <complexType name="restriction_type"><br /> <attribute name="base" type="base_type" use="required"/><br /> </complexType><br /> <complexType name="attribute_type"><br /> <sequence><br /> <element name="simpleType" type="simpleType_type"/><br /> </sequence><br /> <attribute name="use" use="optional"><br /> <simpleType><br /> <restriction base="string"><br /> <enumeration value="optional"/><br /> <enumeration value="required"/><br /> </restriction><br /> </simpleType><br /> </attribute><br /> <attribute name="name" type="NCName" use="required"/><br /> </complexType><br /> <complexType name="extension_type"><br /> <sequence><br /> <element name="attribute" type="attribute_type" minOccurs="0" maxOccurs="unbounded"/><br /> </sequence><br /> <attribute name="base" type="base_type" use="required"/><br /> </complexType><br /> <complexType name="complexType_type"><br /> <choice><br /> <element name="simpleContent"><br /> <complexType><br /> <sequence><br /> <element name="extension" type="extension_type"/><br /> </sequence><br /> </complexType><br /> </element><br /> <sequence><br /> <group ref="sequence_choice" minOccurs="0"/><br /> <element name="attribute" type="attribute_type" minOccurs="0" maxOccurs="unbounded"/><br /> </sequence><br /> </choice><br /> <attribute name="mixed" use="optional"><br /> <simpleType><br /> <restriction base="string"><br /> <enumeration value="true"/><br /> <enumeration value="false"/><br /> </restriction><br /> </simpleType><br /> </attribute><br /> </complexType><br /> <complexType name="simpleType_type"><br /> <sequence><br /> <element name="restriction" type="restriction_type"/><br /> </sequence><br /> </complexType><br /> <group name="sequence_choice"><br /> <choice><br /> <element name="sequence"><br /> <complexType><br /> <group ref="element_sequence_choice" maxOccurs="unbounded"/><br /> </complexType><br /> </element><br /> <element name="choice"><br /> <complexType><br /> <group ref="element_sequence_choice" maxOccurs="unbounded"/><br /> </complexType><br /> </element><br /> </choice><br /> </group><br /></schema></span>Stephen D Greenhttp://www.blogger.com/profile/11733910745267236574noreply@blogger.com1