Using XML In Vi PER and More XML

  • Slides: 21
Download presentation
Using XML In Vi. PER and More

Using XML In Vi. PER and More

XML • Direct access to information, without worrying about parsing. • XML Information Set

XML • Direct access to information, without worrying about parsing. • XML Information Set – XML provides a way to access information independent of access, format, etc. – XML is just a serialization of a set of information arranged in a tree.

Vi. PER Tree • viper – config • descriptor – data • sourcefilename=“file. mpg”

Vi. PER Tree • viper – config • descriptor – data • sourcefilename=“file. mpg” – file – object

Vi. PER File Format <? xml version="1. 0" encoding="UTF-8"? > <viper xmlns="http: //lamp. cfar.

Vi. PER File Format <? xml version="1. 0" encoding="UTF-8"? > <viper xmlns="http: //lamp. cfar. umd. edu/viper" xmlns: data="http: //lamp. cfar. umd. edu/viperdata"> <config> <descriptor name="Information" type="FILE"> <attribute name="SOURCEDIR" dynamic="false" type="svalue"/> </descriptor> </config> <data> <sourcefilename="comm-001_00001. jpg" > <file name="Information" id="0" framespan="0: 0"> <attribute name="SOURCEDIR"><data: svalue="/fs/lampa/Face. Text. DB/JPEG/advertisements" /> </attribute> </file> </sourcefile> </data> </viper>

Accessing Via XPath • Get data from a specific file – /viper/data/sourcefile[@filename=“f. mpg”] •

Accessing Via XPath • Get data from a specific file – /viper/data/sourcefile[@filename=“f. mpg”] • Gets the sourcefile node – //sourcefile[@fname=“f. mpg]//bbox • Gets all bbox nodes

Matlab with Java % Add xerces. jar to classpath. txt (find using 'which classpath.

Matlab with Java % Add xerces. jar to classpath. txt (find using 'which classpath. txt') % need to restart matlab after changing import org. apache. xerces. parsers. * org. w 3 c. dom. *; import java. lang. String org. xml. sax. *; input = Input. Source('C: MATLAB 6 p 1workadvertisements. xml'); parser = DOMParser; parser. set. Feature('http: //apache. org/xml/features/validation/schema', 0) parser. parse(input); doc = parser. get. Document; sfs = doc. get. Elements. By. Tag. Name('sourcefile') files = cell(sfs. get. Length, 1); i = 0; while i < sfs. get. Length fileattr = sfs. item(i). get. Attributes. get. Named. Item('filename'); i = i + 1; files(i) = fileattr. get. Value; end

Perl use XML: : Lib. XML; my $parser = XML: : Lib. XML->new(); my

Perl use XML: : Lib. XML; my $parser = XML: : Lib. XML->new(); my $tree = $parser->parse_file($datafiles[0]); my $root = $tree->get. Document. Element; foreach my $source ($root->findnodes('sourcefile')){ my $image = $source->findvalue('@filename'); foreach my $d ($source->findnodes('content|object')){ [$start. Frame, $end. Frame] = split(/: /, $d->findvalue('@framespan')); foreach my $shape ($d->findnodes(lc($attrib. Type))) { $orig_x = $shape->findvalue( ‘@x' ); $orig_y = $shape->findvalue( ‘@y' );

C with libxml 2 #include <libxml/xmlmemory. h> #include <libxml/parser. h> ---xml. Doc. Ptr doc

C with libxml 2 #include <libxml/xmlmemory. h> #include <libxml/parser. h> ---xml. Doc. Ptr doc = = xml. Parse. File(‘truth. xml’); if (doc == NULL) return(NULL); xml. Node. Ptr cur = xml. Doc. Get. Root. Element(doc); xml. Ns. Ptr viperns = xml. Search. Ns. By. Href(doc, cur, (const xml. Char *) "http: //lamp. cfar. umd. edu/viper"); cur = cur->xml. Children. Node; while (cur != NULL) { if ((!strcmp(cur->name, “config”)) && (cur->ns == viperns)) parse. Config (doc, viperns, cur); else if ((!strcmp(cur->name, “data”)) && (cur->ns == viperns)) parse. Data (doc, viperns, cur); cur = cur->next; } xml. Cleanup. Parser();

XML Databases • Uses existing tools to access persistent data – DOM and XPath

XML Databases • Uses existing tools to access persistent data – DOM and XPath – XQuery and XUpdate • Many different implementations – Open Source: Apache Xindice, e. Xist – Proprietary: Text. ML, X-Hive, – Relational: MS SQL, Oracle

XSL: Transformations • The idea is to look at the incoming data as a

XSL: Transformations • The idea is to look at the incoming data as a tree, using XPath, and select various nodes to copy to the output. • While the output does not have to be XML, the input and the document itself must be well formed. • On system 7, ‘test. XSLT’ runs stylesheets.

XSLT <? xml version=“ 1. 0” encoding=“UTF-8”? > <xsl: stylesheet version=“ 1. 0” xmlns:

XSLT <? xml version=“ 1. 0” encoding=“UTF-8”? > <xsl: stylesheet version=“ 1. 0” xmlns: xsl=“http: //www. w 3. org/1999/XSL/Transform” xmlns: gtf=“http: //lamp. cfar. umd. edu/viper” xmlns: data=“http: //lamp. cfar. umd. edu/viperdata” xmlns: xsi="http: //www. w 3. org/2001/XMLSchema-instance"> <xsl: strip-space elements="gtf: viper"/> <xsl: output method="xml" omit-xml-declaration="yes"/> <!– continued -->

XSLT <xsl: template match="/gtf: viper"> <xsl: text> #VIPER_VERSION_3. 0 1 </xsl: text> <xsl: apply-templates

XSLT <xsl: template match="/gtf: viper"> <xsl: text> #VIPER_VERSION_3. 0 1 </xsl: text> <xsl: apply-templates select="*/"/> </xsl: template> <xsl: template match="//gtf: sourcefile[starts-with(@filename, 'comm-001')]"> <xsl: value-of select="@filename" /> <xsl: text> </xsl: template> </xsl: stylesheet>

CSS-1 • Supported in the majority of browsers in use today. • Basic styling.

CSS-1 • Supported in the majority of browsers in use today. • Basic styling. Hopefully will reduce reliance on HTML tables as a way to lay out web pages. <style type="text/css"> p{ font-size: 12 pt; line-height: 18 pt; } p: first-letter { font-size: 200%; float: left; } </style>

CSS-2 • Added support for pagination, including widow and orphan control, page breaks, and

CSS-2 • Added support for pagination, including widow and orphan control, page breaks, and margins. • Aural style sheets for voice browsing. • Can be applied directly to XML. • Possible to do some multi-column layout.

CSS-3 • Modularized • Through Ruby, support for Japanese, Arabic, etc. • Multi-column layout

CSS-3 • Modularized • Through Ruby, support for Japanese, Arabic, etc. • Multi-column layout • Support for other W 3 C specs, like – SVG – Math. ML – SMIL

XSL: FO • Basically, the idea is to put CSS-2 in an XML dialect,

XSL: FO • Basically, the idea is to put CSS-2 in an XML dialect, and use XPath and other XML technologies to make printed media look nice. • Extremely verbose – designed to be generated from semantic markup. – However, its lack of semantics leads Opera CTO Lie to call them “Harmful. ” • Additions include footnotes, hyphenation, odd/even pages, citations for indices and tables of contents. • Render. X, Apache FOP

Defining an XML Dialect • Document Type Definitions – Simple, BNF type definition of

Defining an XML Dialect • Document Type Definitions – Simple, BNF type definition of tags, attributes, and how they may be arranged. • Schema – XML based replacement for non-XML DTDs. – Complex. – Define data types, and associate them with tag names. • Rule based constriction – Schematron

Vi. PER Schema <? xml version="1. 0" encoding="UTF-8"? > <xsd: schema xmlns: xsd="http: //www.

Vi. PER Schema <? xml version="1. 0" encoding="UTF-8"? > <xsd: schema xmlns: xsd="http: //www. w 3. org/2001/XMLSchema" target. Namespace="http: //lamp. cfar. umd. edu/viper" xmlns: viper="http: //lamp. cfar. umd. edu/viper" element. Form. Default="qualified"> <xsd: element name="viper" type="viper: viper. Type"/> <xsd: complex. Type name="viper. Type"> <xsd: sequence> <xsd: element name="config" type="viper: config. Type"/> <xsd: element name="data" type="viper: data. Type" min. Occurs="0"/> </xsd: sequence> </xsd: complex. Type>

Vi. PER Data Schema <xsd: schema xmlns: xsd=“http: //www. w 3. org/2001/XMLSchema” target. Namespace=“http:

Vi. PER Data Schema <xsd: schema xmlns: xsd=“http: //www. w 3. org/2001/XMLSchema” target. Namespace=“http: //lamp. cfar. umd. edu/viperdata” xmlns: viperdata=“http: //lamp. cfar. umd. edu/viperdata” xmlns: viper=“http: //lamp. cfar. umd. edu/viper” element. Form. Default=“qualified”> <xsd: import namespace=“http: //lamp. cfar. umd. edu/viper” schema. Location=“file: viper. xsd” /> <xsd: element name="point" substitution. Group="viper: null"> <xsd: complex. Type><xsd: complex. Content> <xsd: extension base="viper: descriptor. Attribute. Data"> <xsd: attribute name="x" type="xsd: integer"/> <xsd: attribute name="y" type="xsd: integer"/> </xsd: extension> </xsd: complex. Content></xsd: complex. Type> </xsd: element>

MPEG-7 • Based on XML-Schema. • Extensions to deal better with video type data,

MPEG-7 • Based on XML-Schema. • Extensions to deal better with video type data, including matrix data types, etc. • Designed to work with any level of description, from low level to high. • W 3 C has only a working draft for DOM access to schemas, so using generic MPEG 7 documents is currently difficult.

Resources • www. xml. com – O'Reilly's XML resource • www. w 3. org

Resources • www. xml. com – O'Reilly's XML resource • www. w 3. org – The standards themselves, and lots of good links to implementations. • xml. apache. org – DOM, SAX, and XSLT for C and Java • xmlsoft. org – libxml creators • msdn. microsoft. com/xml – MS-XML parser is the one to use on Windows. • mpeg. telecomitalialab. com – MPEG-7 Working Group • pyxml. sourceforge. net – Using xml with Python. • okmij. org/ftp/Scheme/xml. html – Using XML with Scheme.