Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yockow/swiftxhtml

XHTML parser/generator in Swift.
https://github.com/yockow/swiftxhtml

swift xhtml

Last synced: 24 days ago
JSON representation

XHTML parser/generator in Swift.

Awesome Lists containing this project

README

        

# What is `SwiftXHTML`?

`SwiftXHTML` will provide some functions related to XHTML.
It was originally written as a part of [SwiftCGIResponder](https://github.com/YOCKOW/SwiftCGIResponder),
and is intended to be used by it.

# Requirements

- Swift 5.1
- macOS(>=10.15) or Linux

## Dependencies

![Dependencies](./dependencies.svg)

# Usage

## As a parser

```Swift
import XHTML

let string = """


Title



My Page


Welcome to my page.



"""

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

```Swift
import XHTML

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

/*
-- OUTPUT --

TitleIt's my page.

*/

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

/*
-- OUTPUT --

Title

It's my page.

*/
```

## What are not supported yet...

- XPath
- CSS selector
- CSS parser

# License

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