Presentation is loading. Please wait.

Presentation is loading. Please wait.

Technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 22. Oktober 2009.

Similar presentations


Presentation on theme: "Technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 22. Oktober 2009."— Presentation transcript:

1 technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 22. Oktober 2009

2 technische universität dortmund 2 HTTP Response HTTP/1.0 200 OK Date: Fri, 31 Dec 2008 23:59:59 GMT Content-Type: text/html Content-Length: 1354 Welcome to my new Homepage! (more file contents).

3 technische universität dortmund 3 Sending Message via SMTP Connecting to mailhost via ether... Trying 140.252.1.54... connected 220 noao.edu Sendmail 4.1/SAG-Noao.G89 ready at Mon, 19 Jul 2008 12:47:34 MST >>> HELO sun.tuc.noao.edu 250 noao.edu Hello sun.tuc.noao.edu., pleased to meet you >>> MAIL From: 250... Sender ok >>> RCPT To: 250... Recipient ok >>> DATA 354 Enter mail, end with. on a line by itself >>>. 250 Mail accepted >>> QUIT 221 noao.edu delivering mail

4 technische universität dortmund 4 XML Example Java and XML Brett McLaughlin 3-89721-280-3 Java 2 Micro Edition Eric Giguere 0-471-39065-8 Core Jini W. Keith Edwards 3-8272-9592-0

5 technische universität dortmund 5 SAX Parser (1) Import SAX Classes import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import org.apache.xerces.parsers.SAXParser; …

6 technische universität dortmund 6 SAX Parser (2) Install Parser and Input Stream public class MySAXParser { public void parseFile(String uri) { } public static void main(String[] args) { MySAXParser mySAX = new MySAXParser(); mySAX.parseFile("booklist.xml"); }

7 technische universität dortmund 7 SAX Parser (3) Install ContentHandler and Exceptions public void parseFile(String uri) { XMLReader parser = new SAXParser(); // Create an instance of MyContentHandler ContentHandler myHandler = new MyContentHandler(); parser.setContentHandler(myHandler); try { parser.parse(uri); } catch (IOException e) { System.out.println("Error reading file: " + e.getMessage()); System.exit(1); } catch (SAXException e) { System.out.println("Error parsing file: " + e.getMessage()); System.exit(1); } System.out.println("File parsed successfully!"); }

8 technische universität dortmund 8 SAX Parser (4) ContentHandler class MyContentHandler implements ContentHandler { private Locator locator; public void setDocumentLocator(Locator locator) {…} public void startDocument() throws SAXException {…} public void endDocument() throws SAXException {…} public void startPrefixMapping(String prefix, String uri){…} public void endPrefixMapping(String prefix) throws SAXException {…} … }

9 technische universität dortmund 9 SAX Parser (5) ContentHandler class MyContentHandler implements ContentHandler { public void startElement( String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {…} public void endElement( String namespaceURI, String localName, String qName) throws SAXException {…} … }

10 technische universität dortmund 10 SAX Parser (6) ContentHandler class MyContentHandler implements ContentHandler { public void characters(char[] ch, int start, int length){…} public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {…} public void processingInstruction(String target, String data) throws SAXException {…} public void skippedEntity(String name) throws SAXException {…} }

11 technische universität dortmund 11 Validation Example DTD <!ELEMENT Book (Title, Author, ISBN)> <!ATTLIST Book available CDATA #REQUIRED >

12 technische universität dortmund 12 Validation Example XML Schema

13 technische universität dortmund 13 XML Document Tree Book Title Price Author ISBNContent Chapter XHTML HEADBODY TitleChapter Transforming Document Trees

14 technische universität dortmund 14 Transformations with XSL <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > …Rules…

15 technische universität dortmund 15 Transformations with XSL Rules <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > …Action…

16 technische universität dortmund 16 Transformations with XSL Example of Transformation <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > XPath-Referencing XPath-Filtering

17 technische universität dortmund 17 Transformations with XSL Iterations

18 technische universität dortmund 18 Using DOM public class DOMParserDemo { public void performDemo(String uri) { System.out.println("Parsing XML File: " + uri + "\n\n"); // Instantiate your vendor's DOM parser implementation DOMParser parser = new DOMParser(); parser.setFeature("http://xml.org/sax/features/validation", true); parser.parse(uri); Document doc = parser.getDocument(); … do something with DOM … } public static void main(String[] args) { String uri = args[0]; DOMParserDemo parserDemo = new DOMParserDemo(); parserDemo.performDemo(uri); }

19 technische universität dortmund 19 Using DOM (2) Example for Accessing DOM Nodes public void printNode(Node node, String indent) { switch (node.getNodeType()) { case Node.DOCUMENT_NODE: System.out.println(" \n"); // recurse on each child NodeList nodes = node.getChildNodes(); if (nodes != null) { for (int i=0; i<nodes.getLength(); i++) { printNode(nodes.item(i), ""); } break; case Node.ELEMENT_NODE: case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: case Node.PROCESSING_INSTRUCTION_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.DOCUMENT_TYPE_NODE: }

20 technische universität dortmund 20 Using DOM (2) Example for Accessing DOM Nodes public void printNode(Node node, String indent) { switch (node.getNodeType()) { case Node.DOCUMENT_NODE: case Node.ELEMENT_NODE: String name = node.getNodeName(); System.out.print(indent + "<" + name); NamedNodeMap attributes = node.getAttributes(); for (int i=0; i<attributes.getLength(); i++) { Node current = attributes.item(i); System.out.print(" " + current.getNodeName() + "=\"" + current.getNodeValue() + "\""); } System.out.println(">"); // recurse on each child NodeList children = node.getChildNodes(); if (children != null) { for (int i=0; i<children.getLength(); i++) { printNode(children.item(i), indent + " "); } System.out.println(indent + " "); break; case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: case Node.PROCESSING_INSTRUCTION_NODE: case Node.ENTITY_REFERENCE_NODE: case Node.DOCUMENT_TYPE_NODE: }


Download ppt "Technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 22. Oktober 2009."

Similar presentations


Ads by Google