//: Playground - noun: a place where people can play import XCPlayground import HTMLKit let htmlString = "" + "" + "
" + "HTMLKit is a WHATWG specification-compliant Objective-C library for parsing and serializing HTML documents and document fragments for OSX and iOS.
" + "HTMLKit parses real-world HTML the same way modern web browsers would.
" + "HTMLKit comes armed with a CSS3 Selectors engine for querying the DOM.
" + " " + "" let document = HTMLDocument(string: htmlString) let links = document.querySelectorAll("a[href*='css']") for link in links { print(link["href"]) } let firstLink = document.querySelector("h1 + p > a") print(firstLink) guard let body = document.body else { XCPlaygroundPage.currentPage.finishExecution() } let h2 = HTMLElement(tagName: "h2", attributes: ["class": "heading"]) h2.textContent = "New heading" let p = HTMLElement(tagName: "p", attributes: ["id": "marker", "style": "color: green;"]) p.textContent = "New paragraph" body.appendNodes([h2, p]) let newParagraph = body.firstElementMatchingSelector(idSelector("marker")) body.insertNode(HTMLElement(tagName: "a", attributes: ["href": "http://google.com"]), beforeChildNode: newParagraph) print(body.outerHTML) let filter = HTMLSelectorNodeFilter(selector: nay(typeSelector("p"))) for node in body.nodeIteratorWithShowOptions([.Element], filter: filter) { print(node.innerHTML) } h2.classList.add(["class2", "class3"]) print(h2.outerHTML) h2.classList.toggle("class2")