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/ OK Date: Fri, 31 Dec :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 connected 220 noao.edu Sendmail 4.1/SAG-Noao.G89 ready at Mon, 19 Jul :47:34 MST >>> HELO sun.tuc.noao.edu 250 noao.edu Hello sun.tuc.noao.edu., pleased to meet you >>> MAIL From: Sender ok >>> RCPT To: 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 Java 2 Micro Edition Eric Giguere Core Jini W. Keith Edwards

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

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 …Rules…

15 technische universität dortmund 15 Transformations with XSL Rules …Action…

16 technische universität dortmund 16 Transformations with XSL Example of Transformation 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

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"); // recurse on each child NodeList children = node.getChildNodes(); if (children != null) { for (int i=0; i


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