Florida Atlantic University Department of Computer Science Engineering

  • Slides: 17
Download presentation
Florida Atlantic University Department of Computer Science & Engineering COP 4814 – Web Services

Florida Atlantic University Department of Computer Science & Engineering COP 4814 – Web Services Dr. Roy Levow Part 4 - XML Fall 2006

XML, XPath, XSLT XML support generally limited to IE and Firefox ¢ XML in

XML, XPath, XSLT XML support generally limited to IE and Firefox ¢ XML in IE ¢ Microsoft. Xml. Dom in IE 4. 0 l MSXML Active. X in IE 5. 0+ l • But only on Windows; not on MAC Text uses create. Document() for cross-IE compatability l XML DOM object created from string l Web Services – Fall 2006

XML DOM Navigation ¢ DOM object properties child. Nodes, first. Child, last. Child, l

XML DOM Navigation ¢ DOM object properties child. Nodes, first. Child, last. Child, l parent. Node, next. Sibling, previous. Sibling, l node. Name, node. Type, node. Value l text, attributes l xml l owner. Document – root node l ¢ Navigate tree with these functions Web Services – Fall 2006

IE XML DOM Navigation Examples ¢ Examples: IE DOM creation l Get Elements by

IE XML DOM Navigation Examples ¢ Examples: IE DOM creation l Get Elements by Tag Name l Create Node l Insert Node l Remove Child l Replace Child l Web Services – Fall 2006

IE XML DOM Error Handling Creates and propagates exception object parse. Error ¢ parse.

IE XML DOM Error Handling Creates and propagates exception object parse. Error ¢ parse. Error object provides details ¢ error. Code, reason l file. Pos, line. Pos l src. Text l url l Web Services – Fall 2006

XML DOM in Firefox ¢ Uses create. Document() method to generate DOM object Empty

XML DOM in Firefox ¢ Uses create. Document() method to generate DOM object Empty l From string l From url l load() method loads from a url ¢ String version of XML subtree is produced by XMLSerializer object ¢ Web Services – Fall 2006

XML DOM in Firefox - 2 ¢ Error handling l Firefox produces an error

XML DOM in Firefox - 2 ¢ Error handling l Firefox produces an error document • Not the error object of IE • It can be parsed to get the same information Web Services – Fall 2006

Firefox XML DOM - 3 ¢ Examples: Firefox DOM Dreation l DOM Parser l

Firefox XML DOM - 3 ¢ Examples: Firefox DOM Dreation l DOM Parser l Get text l Serialize l Error handling l Web Services – Fall 2006

Cross-Browser XML ¢ Requires library to create standard calls for operations Text provides z.

Cross-Browser XML ¢ Requires library to create standard calls for operations Text provides z. Xml library l z. Xml. Dom. create. Document() l ¢ Examples: Cross-Browser DOM l Processing Book List Web Services – Fall 2006

XML Namespaces ¢ XML uses namespace concept to resolve naming conflicts between documents from

XML Namespaces ¢ XML uses namespace concept to resolve naming conflicts between documents from different sources Tag name has form ns: tag. Name l Declared as xmlsn: ns-prefix=“ns. URI” l • URI has same syntax as URL but need not be real address • Should be unique • Declarations in root tag of document Web Services – Fall 2006

XPath ¢ XPath expressions l Context node is partial path from which selection begins

XPath ¢ XPath expressions l Context node is partial path from which selection begins • book/author – this parent-child sequence l Selection pattern specifies which nodes to include • book[@isbn=‘ 001001’] • Expressions have own syntax and can be quite complex Web Services – Fall 2006

XPath in IE and Firefox ¢ IE uses two functions select. Single. Node() l

XPath in IE and Firefox ¢ IE uses two functions select. Single. Node() l select. Nodes() l Examples: IE XPath l ¢ Firefox uses two objects XPath. Evaluator l XPath. Result l Examples: Firefox XPath l Web Services – Fall 2006

Cross-Browser XPath ¢ Use z. Xml library l ¢ Same functions as IE Examples:

Cross-Browser XPath ¢ Use z. Xml library l ¢ Same functions as IE Examples: Cross-Browser XPath Web Services – Fall 2006

XSL Transformations ¢ Transformation is done with xsl: stylesheet with XML specific elements l

XSL Transformations ¢ Transformation is done with xsl: stylesheet with XML specific elements l xsl: template to select XMLnodes to process l xsl: variable to select attributes from nodes l ¢ Examples: XSLT Web Services – Fall 2006

XSLT in IE Browser becomes an issue when DOM is used in conjunction with

XSLT in IE Browser becomes an issue when DOM is used in conjunction with XSLT ¢ Must create Active. X XSLTemplate object ¢ Create processor object from template object ¢ transform() method does transformation ¢ l ¢ Result is output property of processor Examples: XSLT in IE Web Services – Fall 2006

Cross-Browser XSLT ¢ Requires library Text provides this in z. Xml l Syntax similar

Cross-Browser XSLT ¢ Requires library Text provides this in z. Xml l Syntax similar to Firefox l ¢ Example: Best Picks Revisited Web Services – Fall 2006

XSLT in Firefox First load XML and XSL into DOM objects ¢ Create XSLTProcessor

XSLT in Firefox First load XML and XSL into DOM objects ¢ Create XSLTProcessor ¢ Import XSL stylesheet l Transform Xml. DOM document or fragment l ¢ Examples: XSL in Firefox Web Services – Fall 2006