SNCA:XML

From Soyjak Wiki, the free ensoyclopedia
(Redirected from XML)
Jump to navigationJump to search

XML (Extensible Markup Language) is a markup langauge best known for being Web 2.0. It stores data in a format readable by machines and humans. It's used for storing lists of items, configuration files and APIs. The jews have tried to replace XML with JSON (derived from JavaScript) but XML is still widely used.

Think of it as HTML but you can have it your way. HTML is not actually XML, as HTML has predefined tags specifically meant for constructing web documents, whereas XML is just for representing arbitrary data.

Many languages, including Java and C#, provide capabilities for parsing XML (for example javax.xml and org.w3c.dom for Java, or System.Xml for C#).

Basic example[edit | edit source]

<?xml version="1.0" encoding="UTF-8"?>
<wiki>
    <article>
        <title>Nophono</title>
        <summary>Nophono is a term that has three meanings. It can be used to describe a piece of boring media, content</summary>
        <views>11702</views>
        <date type="unix">1758719100</date>
    </article>
    <article>
        <title>Pepe</title>
        <summary>Pepe the Frog, also known by a few as the Grinch[1] is an organic classic best known for having</summary>
        <views>121041</views>
        <date type="unix">1644111360</date>
    </article>
</wiki>

What do i do with this .xml file?[edit | edit source]

Parse it. PHP makes this easy. You can also use XSLT but it isn't very common.

PHP[edit | edit source]

<?php
$xml = simplexml_load_file('wiki.xml');
?>
<HTML>
<BODY>
<TABLE>
<?php foreach ($xml->article as $article): ?>
    <TR><TH COLSPAN=2><?php echo $article->title; ?></TH></TR>
    <TR><TH>Summary</TH><TD><?php echo $article->summary; ?></TD></TR>
    <TR><TH>Views</TH><TD><?php echo $article->views; ?></TD></TR>
    <TR><TH>Date created</TH><TD><?php echo date("F j, Y, g:i a", (int)$article->date); ?></TD></TR>
<?php endforeach; ?>
</TABLE>
</BODY>
</HTML>

XSLT[edit | edit source]

Client side XML rendering without javascript. We'll assume the date isn't a unix time unlike the php version for simplicity.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html" indent="yes" />
  <xsl:template match="/">
    <html>
      <body>
        <table>
          <xsl:for-each select="wiki/article">
            <tr>
              <th colspan="2">
                <xsl:value-of select="title"/>
              </th>
            </tr>
            <tr>
              <th>Summary</th>
              <td><xsl:value-of select="summary"/></td>
            </tr>
            <tr>
              <th>Views</th>
              <td><xsl:value-of select="views"/></td>
            </tr>
            <tr>
              <th>Date created</th>
              <td><xsl:value-of select="date"/></td>
            </tr>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

IRC

XML is part of a series on Computer Science.

Languages Low Level AssemblyCC++C#Holy CRust

High Level JavaGoPHPPythonSQLBashJavaScriptPowerShellActionScriptScratchRubyLua

Markup HTMLCSSSVGXML
Software Imageboards nusoiVichanYotsubaOpenYotsuba

OSes WindowsLinuxAndroidTempleOS

Other BabybotMcChallengeSystemdMS PaintJS PaintPhotoshopFlash
AI

ChatGPTGeminiGrokVibe codingGenerative AIStable Diffusion

More SoyGNUCGIDDoSGame developmentPiracyRegexDoxingMicrosoftAppleGoogleDataminingWebPArtificial soyduelRatio duelingCustomizationRicingFSLWindows debloating