SlideShare una empresa de Scribd logo
1 de 29
Descargar para leer sin conexión
XML Processing, Scalate
                              Seminar Softwareentwicklung mit Scala
                                    Wintersemester 2010/11


                                              Martin Hartmann

                                       Friedrich Schiller Universität Jena
                                           Prof. Dr. Wolfram Amme
                                               Christoph Henniger
                                             Christian Schachtzabel


                                               24. Januar 2011




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26
                                                 Prof. Dr. Wolfram Amme                  24. Januar 2011      1/ )
Inhaltsverzeichnisi

   1   Bearbeitung von XML
         Erzeugung eines XML-Datensatz
         Suchen von bestimmten Knoten
         Elemente hinzufügen
         Elemente ändern
         zu guter Letzt
         Load,Save XML
   2   Scalate
         Was ist Scalate
         Scaml - Allgemein
         Scaml - Möglichkeiten
         Einbindung
   3   Quellen


M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26
                                                 Prof. Dr. Wolfram Amme                  24. Januar 2011      2/ )
Extensible Markup Language




          Sprache zur hierarchischen Darstellung
          von Daten
          in Baumstruktur aufgebaut
          perfekt zum plattformunabhängigen
          Datenaustausch (z.B. übers www)




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26
                                                 Prof. Dr. Wolfram Amme                  24. Januar 2011      3/ )
Methoden




          Als normale String-Verarbeitung
          Als Objektgraph (DOM)
          XML-Nodes als Events geparst (SAX)
          Bearbeitung einfacher Bäume




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26
                                                 Prof. Dr. Wolfram Amme                  24. Januar 2011      4/ )
XML aus Strings


   import scala.xml._
   val phoneBook =
          <phonebook>
                 <descr>
                 This is a <b>sample</b> description
                 </descr>
                 <entry>
                 <name>Peter Müller</name>
                 <phone where="work">03643/081542</phone>
                 </entry>
          </phonebook>;
          assert(phoneBook.isInstanceOf[scala.xml.Elem])




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26
                                                 Prof. Dr. Wolfram Amme                  24. Januar 2011      5/ )
Nodes und Elements



   case class Elem(val prefix: String,     // namespace prefix
                 val label: String,        // (local) tag name
                 val attributes: MetaData,
                 val scope: NamespaceBinding, // namespace bindings
                 val child: Node*) extends Node

   Beispiel:
   val bsp = Elem(null,"Beispiel", null, TopScope, null);

   ⇒ <Beispiel></Beispiel>




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26
                                                 Prof. Dr. Wolfram Amme                  24. Januar 2011      6/ )
Work with Elements

   import scala.xml._
   val phoneBook =
       Elem(null, "phonebook", Null, TopScope,
          Elem(null, "descr", Null, TopScope,
               Text("This is a "),
               Elem(null, "b", Null, TopScope, Text("sample")),
               Text("description")
             ),
          Elem(null, "entry", Null, TopScope,
               Elem(null, "name", Null, TopScope, Text("Peter
                   Müller")),
               Elem(null, "phone", new
                   UnprefixedAttribute("where","work", Null),
                   TopScope,
                    Text("03643/082542"))
             )
          )

M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26
                                                 Prof. Dr. Wolfram Amme                  24. Januar 2011      7/ )
Schleifen und Matching I




   for (phone <- (phoneBook"phone")){
          if ((phone@"where").text == "work")
                 println("At Work: " + phone.text)
   }




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26
                                                 Prof. Dr. Wolfram Amme                  24. Januar 2011      8/ )
Schleifen und Matching II



   phoneBook match {
   case <phonebook>{entries @_*}</phonebook>=>
          for (number @ <phone>{_*}</phone> <-entries)
                 println("Numbers: " + number.text)
   case _ => doSmthElse

   andere Möglichkeit der Selektion:
   case Elem(_,"entry", _, _, _*, Elem(_, "foo", _)) => ...




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26
                                                 Prof. Dr. Wolfram Amme                  24. Januar 2011      9/ )
Einträge hinzufügen I




   def add( pBook: Node, newEntry: Node ): Node = pBook match {
        case <phonebook>{ ch @ _*}</phonebook> =>
          <phonebook>{ ch }{ newEntry}</phonebook>
    }




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            10 / )
Einträge hinzufügen II

   add( phoneBook,
          <entry>
                  <name>Werner Schmidt</name>
                  <phone where="home">03643/123456</phone>
          </entry>
   );

   Oder:
   add( phoneBook,
          Elem(null, "entry", Null, TopScope,
                 Elem(null, "name", Null, TopScope, Text("Werner
                     Schmidt")),
                 Elem(null, "phone", new
                     UnprefixedAttribute("where","home", Null),
                     TopScope,
                        Text("03643/123456"))
   )
M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            11 / )
Einträge ändern I




   Annahme einer Funktion “copyOrChange“
   phoneBook match {
       case <phonebook>{ ch @ _* }</phonebook> =>
           <phonebook>{ copyOrChange( ch.elements ) }</phonebook>




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            12 / )
Einträge ändern II



          def copyOrChange ( ch: Iterator[Node] )




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            13 / )
Einträge ändern II



          def copyOrChange ( ch: Iterator[Node] )

          Sprung an die entsprechende Stelle




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            13 / )
Einträge ändern II



          def copyOrChange ( ch: Iterator[Node] )

          Sprung an die entsprechende Stelle

          case x @ <entry><name>{ Text(Name) }</name>{ ch1 @
              _*}</entry> =>




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            13 / )
Einträge ändern II



          def copyOrChange ( ch: Iterator[Node] )

          Sprung an die entsprechende Stelle

          case x @ <entry><name>{ Text(Name) }</name>{ ch1 @
              _*}</entry> =>

          Zugriff mit
          ch1.text




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            13 / )
Einträge ändern III



   Eintrag noch nicht vorhanden:
   <entry>
       <name>{ Name }</name>
       <phone where={ Where }>{ newPhone }</phone>
   </entry>

   Eintrag muss geändert werden:
   <phone where={ Where}>{ newPhone }</phone>




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            14 / )
XML Path Language


   val pp = new PrettyPrinter(80, 5);

   Console.println( pp.formatNodes( phoneBook  "entry" ));

   Ausgabe:
   <entry>
       <name>Peter Müller</name>
       <phone where="work">03643/081542</phone>
   </entry><entry>
       <name>Werner Schmidt</name>
       <phone where="home">03643/123456</phone>
   </entry>




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            15 / )
Fazit




   Verarbeitungskriterien:
          sequenzieller Zugriff
          Pull Ablauf
          hierarchisch strukturiert




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            16 / )
Load und Save XML




   val x = scala.xml.XML.loadFile("myfile.xml");

   scala.xml.XML.save("myfile.xml", Elem(...));




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            17 / )
Was ist Scalate




          Template Engine zum Generieren von Text und
          Markups
          unterstützt verschiedene template-Formate
          (Mustache, Scaml, Jade, SSP)




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            18 / )
Scaml Allgemein




          ’Dialekt’ von Haml
          besser lesbar als bspw. XML
          Allerdings: kein ’Begin’ und ’End’ ,Abtrennung durch einrücken
          ⇒ dadurch bessere Lesbarkeit
          Leerzeichen und Tabs im gesamten Dokument konsistent




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            19 / )
Beispiel



   %one
     %two
       %three Here Text


   <one>
     <two>
       <three>Here Text</three>
     </two>
   </one>




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            20 / )
Klassen, Attribute, IDs



   %div#things
     %span#spicy Chili Con Carne
     %p.beans{ :food => "true" } Something about Beans
     %h1.class.otherclass#more Something more


   <div id="things">
     <span id="spicy">Chili Con Carne</span>
     <p class="beans" food="true">Something about Beans</p>
     <h1 id="more" class="class otherclass">Something more</h1>
   </div>




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            21 / )
Scaml - Doctype

   !!! XML
   %html
     %head
       %title Myspace
     %body
       %h1 I am the international space station


   <?xml version="1.0" encoding="utf-8" ?>
   <html>
     <head>
       <title>Myspace</title>
     </head>
     <body>
       <h1>I am the international space station</h1>
     </body>
   </html>

M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            22 / )
Scala-Funktionen und Scaml



   object Cheese {
     def foo(productId: Int) =
       <a href={"/products/" + productId} title="Product link">
                  My Product
           </a>
   }

   Einbindung in Scaml:
   - import Cheese._
   = foo(123)




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            23 / )
Capture-Funktion

   import org.fusesource.scalate.RenderContext.capture

   object Cheese {
     def foo(productId: Int)(body: => Unit) =
       <a href={"/products/" + productId} title="Product
           link">capture(body)</a>
   }


   -@ val id: Int = 123
   - import Cheese._

   = foo(id)
     product #{id}

   Ergebnis:
   <a href="/products/123" title="Product link">product 123</a>
M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            24 / )
Quellen




          Dean Wampler, Alex Payne
          Programming Scala
          sites.google.com/site/burakemir/scalaxbook.docbk.html
          http://scalate.fusesource.org/documentation/user-guide.html




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            25 / )
Vielen Dank für
                 ihre Aufmerksamkeit




M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011
                                                 Prof. Dr. Wolfram Amme                24. Christian Schachtzabel26
                                                                                                            26 / )

Más contenido relacionado

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Praesentation

  • 1. XML Processing, Scalate Seminar Softwareentwicklung mit Scala Wintersemester 2010/11 Martin Hartmann Friedrich Schiller Universität Jena Prof. Dr. Wolfram Amme Christoph Henniger Christian Schachtzabel 24. Januar 2011 M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26 Prof. Dr. Wolfram Amme 24. Januar 2011 1/ )
  • 2. Inhaltsverzeichnisi 1 Bearbeitung von XML Erzeugung eines XML-Datensatz Suchen von bestimmten Knoten Elemente hinzufügen Elemente ändern zu guter Letzt Load,Save XML 2 Scalate Was ist Scalate Scaml - Allgemein Scaml - Möglichkeiten Einbindung 3 Quellen M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26 Prof. Dr. Wolfram Amme 24. Januar 2011 2/ )
  • 3. Extensible Markup Language Sprache zur hierarchischen Darstellung von Daten in Baumstruktur aufgebaut perfekt zum plattformunabhängigen Datenaustausch (z.B. übers www) M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26 Prof. Dr. Wolfram Amme 24. Januar 2011 3/ )
  • 4. Methoden Als normale String-Verarbeitung Als Objektgraph (DOM) XML-Nodes als Events geparst (SAX) Bearbeitung einfacher Bäume M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26 Prof. Dr. Wolfram Amme 24. Januar 2011 4/ )
  • 5. XML aus Strings import scala.xml._ val phoneBook = <phonebook> <descr> This is a <b>sample</b> description </descr> <entry> <name>Peter Müller</name> <phone where="work">03643/081542</phone> </entry> </phonebook>; assert(phoneBook.isInstanceOf[scala.xml.Elem]) M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26 Prof. Dr. Wolfram Amme 24. Januar 2011 5/ )
  • 6. Nodes und Elements case class Elem(val prefix: String, // namespace prefix val label: String, // (local) tag name val attributes: MetaData, val scope: NamespaceBinding, // namespace bindings val child: Node*) extends Node Beispiel: val bsp = Elem(null,"Beispiel", null, TopScope, null); ⇒ <Beispiel></Beispiel> M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26 Prof. Dr. Wolfram Amme 24. Januar 2011 6/ )
  • 7. Work with Elements import scala.xml._ val phoneBook = Elem(null, "phonebook", Null, TopScope, Elem(null, "descr", Null, TopScope, Text("This is a "), Elem(null, "b", Null, TopScope, Text("sample")), Text("description") ), Elem(null, "entry", Null, TopScope, Elem(null, "name", Null, TopScope, Text("Peter Müller")), Elem(null, "phone", new UnprefixedAttribute("where","work", Null), TopScope, Text("03643/082542")) ) ) M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26 Prof. Dr. Wolfram Amme 24. Januar 2011 7/ )
  • 8. Schleifen und Matching I for (phone <- (phoneBook"phone")){ if ((phone@"where").text == "work") println("At Work: " + phone.text) } M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26 Prof. Dr. Wolfram Amme 24. Januar 2011 8/ )
  • 9. Schleifen und Matching II phoneBook match { case <phonebook>{entries @_*}</phonebook>=> for (number @ <phone>{_*}</phone> <-entries) println("Numbers: " + number.text) case _ => doSmthElse andere Möglichkeit der Selektion: case Elem(_,"entry", _, _, _*, Elem(_, "foo", _)) => ... M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Christian Schachtzabel26 Prof. Dr. Wolfram Amme 24. Januar 2011 9/ )
  • 10. Einträge hinzufügen I def add( pBook: Node, newEntry: Node ): Node = pBook match { case <phonebook>{ ch @ _*}</phonebook> => <phonebook>{ ch }{ newEntry}</phonebook> } M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 10 / )
  • 11. Einträge hinzufügen II add( phoneBook, <entry> <name>Werner Schmidt</name> <phone where="home">03643/123456</phone> </entry> ); Oder: add( phoneBook, Elem(null, "entry", Null, TopScope, Elem(null, "name", Null, TopScope, Text("Werner Schmidt")), Elem(null, "phone", new UnprefixedAttribute("where","home", Null), TopScope, Text("03643/123456")) ) M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 11 / )
  • 12. Einträge ändern I Annahme einer Funktion “copyOrChange“ phoneBook match { case <phonebook>{ ch @ _* }</phonebook> => <phonebook>{ copyOrChange( ch.elements ) }</phonebook> M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 12 / )
  • 13. Einträge ändern II def copyOrChange ( ch: Iterator[Node] ) M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 13 / )
  • 14. Einträge ändern II def copyOrChange ( ch: Iterator[Node] ) Sprung an die entsprechende Stelle M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 13 / )
  • 15. Einträge ändern II def copyOrChange ( ch: Iterator[Node] ) Sprung an die entsprechende Stelle case x @ <entry><name>{ Text(Name) }</name>{ ch1 @ _*}</entry> => M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 13 / )
  • 16. Einträge ändern II def copyOrChange ( ch: Iterator[Node] ) Sprung an die entsprechende Stelle case x @ <entry><name>{ Text(Name) }</name>{ ch1 @ _*}</entry> => Zugriff mit ch1.text M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 13 / )
  • 17. Einträge ändern III Eintrag noch nicht vorhanden: <entry> <name>{ Name }</name> <phone where={ Where }>{ newPhone }</phone> </entry> Eintrag muss geändert werden: <phone where={ Where}>{ newPhone }</phone> M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 14 / )
  • 18. XML Path Language val pp = new PrettyPrinter(80, 5); Console.println( pp.formatNodes( phoneBook "entry" )); Ausgabe: <entry> <name>Peter Müller</name> <phone where="work">03643/081542</phone> </entry><entry> <name>Werner Schmidt</name> <phone where="home">03643/123456</phone> </entry> M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 15 / )
  • 19. Fazit Verarbeitungskriterien: sequenzieller Zugriff Pull Ablauf hierarchisch strukturiert M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 16 / )
  • 20. Load und Save XML val x = scala.xml.XML.loadFile("myfile.xml"); scala.xml.XML.save("myfile.xml", Elem(...)); M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 17 / )
  • 21. Was ist Scalate Template Engine zum Generieren von Text und Markups unterstützt verschiedene template-Formate (Mustache, Scaml, Jade, SSP) M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 18 / )
  • 22. Scaml Allgemein ’Dialekt’ von Haml besser lesbar als bspw. XML Allerdings: kein ’Begin’ und ’End’ ,Abtrennung durch einrücken ⇒ dadurch bessere Lesbarkeit Leerzeichen und Tabs im gesamten Dokument konsistent M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 19 / )
  • 23. Beispiel %one %two %three Here Text <one> <two> <three>Here Text</three> </two> </one> M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 20 / )
  • 24. Klassen, Attribute, IDs %div#things %span#spicy Chili Con Carne %p.beans{ :food => "true" } Something about Beans %h1.class.otherclass#more Something more <div id="things"> <span id="spicy">Chili Con Carne</span> <p class="beans" food="true">Something about Beans</p> <h1 id="more" class="class otherclass">Something more</h1> </div> M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 21 / )
  • 25. Scaml - Doctype !!! XML %html %head %title Myspace %body %h1 I am the international space station <?xml version="1.0" encoding="utf-8" ?> <html> <head> <title>Myspace</title> </head> <body> <h1>I am the international space station</h1> </body> </html> M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 22 / )
  • 26. Scala-Funktionen und Scaml object Cheese { def foo(productId: Int) = <a href={"/products/" + productId} title="Product link"> My Product </a> } Einbindung in Scaml: - import Cheese._ = foo(123) M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 23 / )
  • 27. Capture-Funktion import org.fusesource.scalate.RenderContext.capture object Cheese { def foo(productId: Int)(body: => Unit) = <a href={"/products/" + productId} title="Product link">capture(body)</a> } -@ val id: Int = 123 - import Cheese._ = foo(id) product #{id} Ergebnis: <a href="/products/123" title="Product link">product 123</a> M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 24 / )
  • 28. Quellen Dean Wampler, Alex Payne Programming Scala sites.google.com/site/burakemir/scalaxbook.docbk.html http://scalate.fusesource.org/documentation/user-guide.html M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 25 / )
  • 29. Vielen Dank für ihre Aufmerksamkeit M. Hartmann (Friedrich Schiller Universität Jena XML Processing, Scalate Christoph Henniger Januar 2011 Prof. Dr. Wolfram Amme 24. Christian Schachtzabel26 26 / )