About Users Other Info (External) |
Main /
Tutorials1This tutorial is meant as a first exposure to the tools and as such, is the simplest possible example for Squash that I could think of. We will create all the files we need, run Squash, and view the output.
Getting our ducks in a rowWe first need to create/organize some files and our working environment. What tXMLSchema has already given us
What we need to create ourselves
$ cd $TXSCHEMA/src/test_cases $ mkdir myRun1 $ cd myRun1
<?xml version="1.0" encoding="UTF-8"?> <!-- mySnapshotSchema.xsd. Created by Stephen W. Thomas as a simple example. June 2008. --> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xsd:element name="person"> <xsd:complexType mixed="true"> <xsd:sequence> <xsd:element ref="personData"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="personData"> <xsd:complexType mixed="true"> <xsd:sequence> <xsd:element name="personID" type="xsd:integer" minOccurs="1" maxOccurs="1"/> <xsd:element name="firstName" type="xsd:string" minOccurs="1" maxOccurs="1"/> <xsd:element name="salary" type="xsd:string" minOccurs="1" maxOccurs="1"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
<?xml version="1.0" encoding="UTF-8"?> <person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./mySnapshotSchema.xsd"> <personData> <personID>67</personID> <firstName>Steve</firstName> <salary>45000</salary> </personData> </person>
<?xml version="1.0" encoding="UTF-8"?> <person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./mySnapshotSchema.xsd"> <personData> <personID>67</personID> <firstName>Steve</firstName> <salary>51000</salary> </personData> </person>
$ xmllint --schema mySnapshotSchema.xsd salary_version1.xml $ xmllint --schema mySnapshotSchema.xsd salary_version2.xml After each of the above commands, a line similar to "salary_version1.xml validates" should be displayed to
<?xml version="1.0" encoding="utf-8"?> <annotationSet xmlns="http://www.cs.arizona.edu/tau/ASchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.cs.arizona.edu/tau/ASchema ../../../etc/ASchema.xsd"> <logical> <item target="salary"> <transactionTime kind="state" content="varying" existence="constant" /> <itemIdentifier name="@text" timeDimension="transactionTime"> <field path="/@text"/> </itemIdentifier> </item> </logical> <physical> <default> <format plugin="XMLSchema" granularity="days"/> </default> <stamp target="salary"> <stampKind timeDimension="transactionTime" stampBounds="extent" /> </stamp> </physical> </annotationSet>
xmllint --schema ../../../etc/ASchema.xsd Annotations.xml
<?xml version="1.0" encoding="utf-8"?> <temporalSchema xmlns="http://www.cs.arizona.edu/tau/TSSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.cs.arizona.edu/tau/TSSchema ../../../etc/TSSchema.xsd"> <conventionalSchema> <include schemaLocation="mySnapshotSchema.xsd"/> </conventionalSchema> <annotationSet> <include location="Annotations.xml"/> </annotationSet> </temporalSchema>
xmllint --schema ../../../etc/TSSchema.xsd myTempSchema.xml
<?xml version="1.0" encoding="utf-8"?> <temporalRoot xmlns="http://www.cs.arizona.edu/tau/TDSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.cs.arizona.edu/tau/TDSchema ../../../etc/TDSchema.xsd"> <temporalSchemaSet> <temporalSchema schemaLocation="./myTempSchema.xml"/> </temporalSchemaSet> <sliceSequence> <slice location="./salary_version1.xml" begin="2002-06-21" end="2002-06-22"/> <slice location="./salary_version2.xml" begin="2002-06-22" end="2002-06-23"/> </sliceSequence> </temporalRoot>
xmllint --schema ../../../etc/TDSchema.xsd temporalSalary.xml
Running SquashAssuming the installation is complete and your environment is setup correctly, running squash is easy: $ squash temporalSalary.xml
Viewing OutputThe output of squash is "temporalSalary_squashed.xml", which is another temporal document that summaries all the versions of the "Non-Temporal" XML documents. The file should look something like:
<?xml version="1.0" encoding="UTF-8"?> <temporalRoot xmlns:tv="http://www.cs.arizona.edu/tau/TVSchema" begin="2002-06-21" end="2002-06-23"> <temporalSchemaSet> <temporalSchema schemaLocation="./myTempSchema.xml"/> </temporalSchemaSet> <person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <personData> <personID>67</personID> <firstName>Alex</firstName> <salary_RepItem isItem="y" originalElement="salary"> <salary_Version> <tv:timestamp_TransExtent begin="2002-06-21" end="2002-06-22"/> <salary>45000</salary> </salary_Version> <salary_Version> <tv:timestamp_TransExtent begin="2002-06-22" end="2002-06-23"/> <salary>51000</salary> </salary_Version> </salary_RepItem> </personData> </person> </temporalRoot>
|