Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback

JSX for XML

Yet another JSX runtime, but for XML, built for Deno!

Usage

/** @jsx xml.createElement */
/** @jsx xml.Fragment */

import * as xml from "https://deno.land/x/jsx4xml/mod.ts";
console.log(xml.renderToString(<hello place="world" />));

Via React compartible mode

import * as React from "https://deno.land/x/jsx4xml/mod.ts";
console.log(React.renderToString(<hello place="world" />));

Example

RSS

/** @jsx xml.createElement */

import * as xml from "https://deno.land/x/jsx4xml/mod.ts";

interface Item {
  title: string;
  link: string;
}

const Rss = ({ items }: { items: Item[] }) => (
  <rss version="2.0">
    <channel>
      <title>Channel Title</title>
      <link>http://example.com</link>
      <description>Channel Description</description>
      {items.map((item) => (
        <item>
          <title>{item.title}</title>
          <link>{item.link}</link>
        </item>
      ))}
    </channel>
  </rss>
);

console.log(
  // Add XML declaration at the beginning
  xml.renderWithDeclaration(
    <Rss
      items={[
        { title: "title0", link: "https://example.com/posts/0/" },
        { title: "title1", link: "https://example.com/posts/1/" },
      ]}
    />,
  ),
);