NDHpple

2.0.1

NDHpple is a Swift wrapper on the XMLPathQuery library.
nacho4d/NDHpple

What's New

Rebumped

2020-10-10T14:34:35Z

It is been a long time and this is a stable version 2.0.0 plus some aesthetic fixes (to be more swift like)

Below are all changes since version 1.x

  • Updated everything to swift5.2.
  • Renamed initializers: NDHpple(XMLData:) -> NDHpple(xmlData:) and NDHpple(HTMLData:) -> NDHpple(htmlData:).
  • Use structs instead of classes in various places.
  • Internally cleaned and updated code to look like to recent code conventions (enums are defined with non capitals, etc).
  • Removed dependency in Clibxml2 since libxml can be directly imported in recent versions of swift.
  • Moved example code to test target.
  • Added github actions for building, testing and reporting code coverage in CodeCov (Currently code coverage is about 97% ).
  • Formatted and linted with swift-format.

DESCRIPTION

NDHpple is a simple Swift wrapper on the XMLPathQuery library based on Hpple.

Actions Status codecov.io

CREDITS

NDHpple was created by Nicolai Davidsson, based on Hpple by Geoffrey Grosenbach, Topfunky Corporation.

INSTALLATION

Use swift package manager with url of this repository and then select a version. Old swift versions used to require to link libxml library but this problem has been fixed. No extra steps required.

USAGE

See Tests/NDHppleTests/NDHppleTests.swift for more detailed samples.

import NDHpple

// read xml into a string
let html = """
    <!DOCTYPE html>
    <html>
        <body>
            <p>My first paragraph.</p>
            <p>My last paragraph.</p>
        </body>
    </html>
    """
// initialize parser
let parser = NDHpple(htmlData: html)

let pNodes = parser.search(withQuery: "//p")
print(pNodes[0].text) // "My first paragraph."
print(pNodes[1].text) // "My last paragraph."

let pNode = parser.peekAtSearch(withQuery: "//p[1]")
print(pNode?.text ?? "") // "My first paragraph."

Description

  • Swift Tools 5.2.0
View More Packages from this Author

Dependencies

  • None
Last updated: Tue Mar 26 2024 14:35:30 GMT-0900 (Hawaii-Aleutian Daylight Time)