Använd vänsterpil och högerpil för att navigera

Eller Ctrl+P för att skriva ut till PDF (eller på papper)

XML

XML

Representationer av data

Olika representationer

Ett XML-dokument är ett träd

Exempel på träd

Samma träd i XML

  1. <?xml version="1.0"?>
  2. <Carl>
  3. <Victoria>
  4. <Estelle></Estelle>
  5. <Oscar></Oscar>
  6. </Victoria>
  7. <CarlPhilip>
  8. <Alexander></Alexander>
  9. <Gabriel></Gabriel>
  10. </CarlPhilip>
  11. <Madeleine>
  12. <Leonore></Leonore>
  13. <Nicolas></Nicolas>
  14. </Madeleine>
  15. </Carl>

Typer av noder i XML

Mindre vanliga/viktiga typer av noder

Element

  1. <country code="SE">
  2. <name>Sweden</name>
  3. <city>Stockholm</city>
  4. <city>Gothenburg</city>
  5. <city>Malmö</city>
  6. <stats>
  7. <population>10065389</population>
  8. <area>450295</area>
  9. </stats>
  10. </country>

Attribut

  1. <person name="Jakob" age="30" height="1.81" employed="true">
  2. <skill>C#</skill>
  3. <skill>SQL</skill>
  4. </person>

Text

  1. <paragraph>This is a paragraph with some <red>highlighted</red> text.</paragraph>
  2. <!-- eller: -->
  3. <paragraph>
  4. This is a paragraph with some
  5. <red>highlighted</red>
  6. text.
  7. </paragraph>

Val av XML-representation

Lista med "lösa" element

  1. <movie>
  2. <title>Signs</title>
  3. <actor>Mel Gibson</actor>
  4. <actor>Joaquin Phoenix</actor>
  5. <actor>Abigail Breslin</actor>
  6. <actor>Rory Culkin</actor>
  7. </movie>

Vad betyder detta?

  1. <movie>
  2. <actor>Mel Gibson</actor>
  3. <actor>Joaquin Phoenix</actor>
  4. <title>Signs</title>
  5. <actor>Abigail Breslin</actor>
  6. <actor>Rory Culkin</actor>
  7. </movie>

Lista med grupperade element

  1. <movie>
  2. <title>Signs</title>
  3. <actors>
  4. <actor>Mel Gibson</actor>
  5. <actor>Joaquin Phoenix</actor>
  6. <actor>Abigail Breslin</actor>
  7. <actor>Rory Culkin</actor>
  8. </actors>
  9. </movie>

Vad betyder detta?

  1. <movie>
  2. <title>Signs</title>
  3. <actors>
  4. <actor>Mel Gibson</actor>
  5. <actor>Joaquin Phoenix</actor>
  6. </actors>
  7. <actors>
  8. <actor>Abigail Breslin</actor>
  9. <actor>Rory Culkin</actor>
  10. </actors>
  11. </movie>

Lista med attribut

Element och attribut

  1. <book last-edit-date="2017-01-02">
  2. <title>How to Repair Bicycles</title>
  3. </book>

Enbart element

  1. <book>
  2. <last-edit-date>2017-01-02</last-edit-date>
  3. <title>How to Repair Bicycles</title>
  4. </book>

Enbart attribut

  1. <book last-edit-date="2017-01-02" title="How to Repair Bicycles"></book>
  2. <!-- eller: -->
  3. <book
  4. last-edit-date="2017-01-02"
  5. title="How to Repair Bicycles">
  6. </book>

Vanlig princip: data i element, metadata i attribut

  1. <book last-edit-date="2017-01-02, 2017-03-04, 2017-05-06">
  2. <title>How to Repair Bicycles</title>
  3. </book>

Mindre opålitlig princip

Rotnod

  1. <person name="Angelina"/>
  2. <person name="Brad"/>
  1. <people>
  2. <person name="Angelina"/>
  3. <person name="Brad"/>
  4. </people>

Tomma element

  1. <something></something>
  2. <!-- likvärdigt med: -->
  3. <something/>
  1. <something abc="123"/>

Skiljetecken, stora/små bokstäver

  1. <PascalCase/>
  2. <camelCase/>
  3. <underscore_case/>
  4. <hyphen-case/>

Verkar XML flummigt?

Större exempel

  1. <artist name="Red Hot Chili Peppers">
  2. <member first="Anthony" last="Kiedis"/>
  3. <member .../>
  4. <album title="Californication" release="1999-06-08">
  5. <song title="Around the World" length="123">
  6. <lyrics>All around the world...</lyrics>
  7. </song>
  8. <song ...>...</song>
  9. </album>
  10. <album ...>...</album>
  11. </artist>
  12. <artist ...>...</artist>

Gemensamma värden

Referenser till gemensamma värden

  1. <artist name="Red Hot Chili Peppers">
  2. <member person="1"/>
  3. <member person="2"/>
  4. <member person="3"/>
  5. <member person="4"/>
  6. <album title="Californication" release="1999-06-08">
  7. <song title="Around the World" length="123">
  8. <lyrics>All around the world...</lyrics>
  9. <composer person="1"/>
  10. <composer person="3"/>
  11. </song>
  12. </album>
  13. </artist>
  14. <person id="1" first="Anthony" last="Kiedis"/>
  15. <person id="2" first="Michael" last="Balzary"/>
  16. <person id="3" first="John" last="Frusciante"/>
  17. <person id="4" first="Chad" last="Smith"/>

Upprepade gemensamma värden

  1. <artist name="Red Hot Chili Peppers">
  2. <member first="Anthony" last="Kiedis"/>
  3. <member first="Michael" last="Balzary"/>
  4. <member first="John" last="Frusciante"/>
  5. <member first="Chad" last="Smith"/>
  6. <album title="Californication" release="1999-06-08">
  7. <song title="Around the World" length="123">
  8. <lyrics>All around the world...</lyrics>
  9. <composer first="Anthony" last="Kiedis"/>
  10. <composer first="John" last="Frusciante"/>
  11. </song>
  12. </album>
  13. </artist>

Vilket ska man välja?

XML i SQL

Sammanfattning