1 / 14

XML

XML. ”Ett nytt universellt språk för att representera data på webben”. SGML, HTML och XML. SGML. XML. HTML. XSL och CSS. XML-kodad information Dokument. <brev> <adressat> <namn> Johan Johansson </namn> <gatuadress> Storgatan 1 </gatuadress>

hina
Download Presentation

XML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. XML ”Ett nytt universellt språk för att representera data på webben”

  2. SGML, HTML och XML SGML XML HTML

  3. XSL och CSS XML-kodad information Dokument <brev> <adressat> <namn>Johan Johansson</namn> <gatuadress>Storgatan 1</gatuadress> <postadress>123 45 Stockholm</postadress> </adressat> <rubrik>Hejsan! </rubrik> <brevstomme>Med anledning av...</brevstomme> </brev> Johan Johansson Storgatan 1 123 45 Stockholm Hejsan! Med anledning av... Layoutmall kodad enligt XSL eller CSS XSL – eXtensible Stylesheet Language CSS – Cascading StyleSheet

  4. Datamodellen för XML <Adressbok> <Bekant> <Namn>Stina</Namn> <Intresse>Tennis</Intresse> </Bekant> <Bekant> <Namn>Per</Namn> <Intresse>Fiske</Intresse> </Bekant> </Adressbok>

  5. XML Schema <?xml version=”1.0”?> <Schema xmlns=”urn:schema-microsoft-com:xml-data” xmlns:dt=”urn:schemas-microsoft-com:datatypes”> <ElementType name=”Fornamn” content=”TextOnly” /> <ElementType name=”Efternamn” content=”TextOnly” /> <ElementType name=”Bekant” content=”eltOnly” order=”one”> <group order=”seq”> <element type=”Efternamn” /> <element type=”Fornamn” /> </group> </ElementType> <ElementType name=”Adressbok” content=”eltOnly” > <element type=”Bekant” /> </ElementType> </Schema>

  6. Objektet XMLTextReader <%@ Page Language=”VB” %> <%@ Import Namespace=”System.Xml” %> <script runat=”server”> sub Page_Load(obj as object, e as eventargs) dim reader as XMLTextReader try reader = new XmlTextReader(Server.MaphPath (”adress.xml”)) While reader.Read() Response.Write(reader.Name & ” ” & reader.Value & ”<br>” End While catch ex as Exeption Response.Write(”Fel vid inläsning av XML-dokument”) end try end sub </script <html><body></body></html>

  7. Objektet XMLTextWriter dim writer as XMLTextWriter try writer = new XMLTextWriter(c:\temp\adress.xml), nothing) writer.WriteStartDocument writer.WriteStartElement(”Adressbok”) writer.WriteElementString(”Namn”, ”Bo Ek”) writer.WriteEndElement() writer.Flush catch ex as Exception Response.Write(”Error!”) finally writer.Close end try

  8. Validering av XML • Validering med hjälp av Schema dim validator as new XMLValidatingReader(reader) Validator.ValiadationType = ValidationType.XDR • Validering med hjälp av DTDdim validator as new XMLValidatingReader(reader) Validator.ValiadationType = ValidationType.DTD

  9. XML DOM XMLDocumnet XMLNode XML Document Object Model XML-data XMLTextReader XMLTextReader

  10. Hämta XML-data • Via XMLTextReader dim MyXMLDoc as XMLDocument = new XMLDocument() dim reader as new XMLTextReader(”c:\temp\test.xml”) MyXMLDoc.Load(reader) • Direkt från XML-fil dim MyXMLDoc as XMLDocument = new XMLDocument() MyXMLDoc.Load(”c:\temp\test.xml”)

  11. Skapa och modifera XML-data dim eleBook as XmlElement = xml.CreateElement (”Book”) dim attStyle as XmlAttribute = xmldoc.CreateAttribute(”style”) eleBook.SetAttributeNode(attStyle) eleBook.SetAtribute(”style”, ”hardback”) dim root as XmlElement = xmldoc.Item(”bookstore”) Root.AppendChild(eleBook) ------ if node.Name = ”price” then node.Value = ”125” end if

  12. XML och DataSet XML-Fil Databas XmlTextReader ADO.Net (el.dyl.) XmlDataDocument DataSet Validering mm Data binding mm

  13. Övergång: XML till DataSet • Element med attribut blir tabeller • Element med underelement lika så • Element med samma namn blir tabeller • Barn till root-noden blir tabeller Observera: Begränsningar i hanteringen av relationer

  14. Avslutningsvis ”XML will make the web look more like a library and less like a messy heap of books on the floor” R.V. Guha, Netscape

More Related