XHTML

3.0.0

XHTML parser/generator in Swift.
YOCKOW/SwiftXHTML

What's New

Release v3.0.0.

2026-03-23T08:15:18Z

What's Changed

  • Update the dependencies files. (2026-03-23 07:57:30+0000) by @github-actions[bot] in #48
  • Update dependencies. by @YOCKOW in #49

New Contributors

  • @github-actions[bot] made their first contribution in #48

Full Changelog: 2.8.0...3.0.0

What is SwiftXHTML?

SwiftXHTML will provide some functions related to XHTML.
It was originally written as a part of SwiftCGIResponder, and is intended to be used by it.

Requirements

  • Swift >=6.2
  • macOS(>=13) or Linux

Dependencies

---
title: XHTML Dependencies
---
flowchart TD
  swiftbootstring(["Bootstring<br>@1.2.0"])
  swiftnetworkgear(["NetworkGear<br>@0.20.0"])
  swiftpublicsuffix(["PublicSuffix<br>@2.4.13"])
  swiftranges(["Ranges<br>@4.0.1"])
  swiftstringcomposition(["StringComposition<br>@3.0.0"])
  swifttemporaryfile(["TemporaryFile<br>@5.0.0"])
  swiftunicodesupplement(["UnicodeSupplement<br>@2.0.0"])
  swiftxhtml["XHTML"]
  yswiftextensions(["yExtensions<br>@2.0.0"])

  click swiftbootstring href "https://github.com/YOCKOW/SwiftBootstring.git"
  click swiftnetworkgear href "https://github.com/YOCKOW/SwiftNetworkGear.git"
  click swiftpublicsuffix href "https://github.com/YOCKOW/SwiftPublicSuffix.git"
  click swiftranges href "https://github.com/YOCKOW/SwiftRanges.git"
  click swiftstringcomposition href "https://github.com/YOCKOW/SwiftStringComposition.git"
  click swifttemporaryfile href "https://github.com/YOCKOW/SwiftTemporaryFile.git"
  click swiftunicodesupplement href "https://github.com/YOCKOW/SwiftUnicodeSupplement.git"
  click yswiftextensions href "https://github.com/YOCKOW/ySwiftExtensions.git"

  swiftnetworkgear ----> swiftbootstring
  swiftnetworkgear ----> swiftpublicsuffix
  swiftnetworkgear ----> swiftranges
  swiftnetworkgear --> swifttemporaryfile
  swiftnetworkgear --> swiftunicodesupplement
  swiftnetworkgear --> yswiftextensions
  swiftstringcomposition --> yswiftextensions
  swifttemporaryfile ----> swiftranges
  swifttemporaryfile --> yswiftextensions
  swiftunicodesupplement ----> swiftranges
  swiftxhtml --> swiftnetworkgear
  swiftxhtml ----> swiftranges
  swiftxhtml --> swiftstringcomposition
  swiftxhtml --> swiftunicodesupplement
  swiftxhtml --> yswiftextensions
  yswiftextensions ----> swiftranges
  yswiftextensions --> swiftunicodesupplement


Loading

Usage

As a parser

import XHTML

let string = """
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Title</title>
  </head>
  <body>
    <div id="main">
      <h1>My Page</h1>
      <p>Welcome to my page.</p>
    </div>
  </body>
</html>
"""

let document = try Parser.parse(string.data(using: .utf8)!)

print(document.prolog.xmlVersion) // -> "1.0"
print(document.element(for: "main")!.name) // -> "div"

As a generator

import XHTML

let page = Document.template(title: "Title",
                             contents:[.text("It's my page.")])
print(page.xhtmlString)

/*
-- OUTPUT --
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Title</title></head><body>It&apos;s my page.</body></html>

*/

page.rootElement.body!.append(.comment("This is a comment."))
print(page.prettyXHTMLString)

/*
-- OUTPUT --
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>Title</title></head>
    <body>
        It&apos;s my page.
        <!--This is a comment.-->
    </body>
</html>

*/

What are not supported yet...

  • XPath
  • CSS selector
  • CSS parser

License

MIT License.
See "LICENSE.txt" for more information.

Description

  • Swift Tools 6.2.0
View More Packages from this Author

Dependencies

Last updated: Fri Jul 31 2026 22:31:33 GMT-0900 (Hawaii-Aleutian Daylight Time)