Origami.

xmlParse(xml)

This parses the given XML text into a DOM structure, which it returns as a plain JavaScript object. This object has the same format used by the related Origami.htmlParse builtin. See also support for XML files.

Example #

Suppose you have an OPML document called blogs.opml that lists a set of blogs in XML format:

<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0">
  <head>
    <title>
      Blogs using Web Origami
    </title>
  </head>
  <body>
    <outline
      type="rss"
      text="Jim Nielsen's Blog"
      htmlUrl="https://blog.jim-nielsen.com"
      xmlUrl="https://blog.jim-nielsen.com/feed.xml"
    />
    <outline
      type="rss"
      text="Posts and notes from Nick Simson"
      htmlUrl="https://www.nicksimson.com"
      xmlUrl="https://www.nicksimson.com/feed.xml"
    />
    <outline
      type="rss"
      text="Vale.Rocks Posts"
      htmlUrl="https://vale.rocks"
      xmlUrl="https://vale.rocks/posts/feed.xml"
    />
  </body>
</opml>

You can use xmlParse to parse this into a plain JavaScript object. In YAML form, the output will be:

name: opml
attributes:
  version: "2.0"
children:
  - name: head
    children:
      - name: title
        text: Blogs using Web Origami
  - name: body
    children:
      - name: outline
        attributes:
          type: rss
          text: Jim Nielsen's Blog
          htmlUrl: https://blog.jim-nielsen.com
          xmlUrl: https://blog.jim-nielsen.com/feed.xml
      - name: outline
        attributes:
          type: rss
          text: Posts and notes from Nick Simson
          htmlUrl: https://www.nicksimson.com
          xmlUrl: https://www.nicksimson.com/feed.xml
      - name: outline
        attributes:
          type: rss
          text: Vale.Rocks Posts
          htmlUrl: https://vale.rocks
          xmlUrl: https://vale.rocks/posts/feed.xml

You could use this data, for example, to render a blogroll to suggest blogs your own readers might be interested in. The following Origami template document calls the Origami.xmlParse function to convert the XML text to a plain object, which is then rendered as HTML:

<!-- Links to each blog in the OPML file -->
<h2>Blogroll</h2>
<ul>
  ${ Tree.map(
    Origami.xmlParse(blogs.opml).children[1].children,
    (outline) => Tree.indent`
      <li>
        <a href="${outline.attributes.htmlUrl}">${outline.attributes.text}</a>
      </li>
    `
  )}
</ul>

Running this produces a list of links for the blogs:

$ ori "blogroll.ori.html()"
<!-- Links to each blog in the OPML file -->
<h2>Blogroll</h2>
<ul>
  <li>
    <a href="https://blog.jim-nielsen.com">Jim Nielsen's Blog</a>
  </li>
  <li>
    <a href="https://www.nicksimson.com">Posts and notes from Nick Simson</a>
  </li>
  <li>
    <a href="https://vale.rocks">Vale.Rocks Posts</a>
  </li>
</ul>