Files
HTMLKit/HTMLKit.playground/Pages/Parsing Documents.xcplaygroundpage/Contents.swift
T
2016-09-20 19:27:05 +02:00

31 lines
581 B
Swift

//: [Previous](@previous)
/*:
# Parsing HTML Documents
*/
import HTMLKit
/*:
Given some HTML content
*/
let htmlString = "<div><h1>HTMLKit</h1><p class='greeting'>Hello there!</p><p class='description'>This is a demo of HTMLKit</p></div>"
htmlString
/*:
You can parse it using the HTMLParser:
*/
let parser = HTMLParser(string: htmlString)
let documentViaParser = parser.parseDocument()
documentViaParser.innerHTML
/*:
You can also create a document from a given HTML string directly:
*/
let document = HTMLDocument(string: htmlString)
document.innerHTML
//: [Next](@next)