--- name: bx-jsoup description: "Use this skill when parsing, querying, or sanitizing HTML in BoxLang with the bx-jsoup module: htmlParse(), htmlClean(), CSS selectors, XSS protection, HTML to JSON/XML conversion, and safe HTML allowlisting." --- # bx-jsoup: HTML Parsing & Sanitization > BoxLang is the AI-native software productivity platform for building, modernizing and running applications, with developers and AI agents working together. ## Installation ```bash install-bx-module bx-jsoup # CommandBox box install bx-jsoup ``` ## BIFs | BIF | Description | |-----|-------------| | `htmlParse( html )` | Parse HTML into a BoxDocument object for querying | | `htmlClean( html, [safelist], [baseUri] )` | Sanitize HTML, removing unsafe tags/attributes | ## HTML Parsing with `htmlParse()` ```javascript // Parse HTML into a document doc = htmlParse( "
Hello
", "none" ) // Returns: "Hello" // Strip scripts but keep basic formatting safe = htmlClean( "BoldText
", "basic" ) // Returns: BoldText
// Rewrite relative URLs to absolute safe = htmlClean( 'Link', "basic", "https://example.com" ) // Returns: Link ``` ## Common Patterns ```javascript // Sanitize user-submitted HTML from a rich text editor function sanitizeRichText( html ) { return htmlClean( html, "basicWithImages" ) } // Extract all links from a page function extractLinks( html ) { var doc = htmlParse( html ) var links = doc.select( "a[href]" ) return links.map( el => el.attr( "href" ) ) } // Scrape structured data function scrapePrices( html ) { var doc = htmlParse( html ) var prices = doc.select( ".price" ) return prices.map( el => el.text() ) } ``` ## Common Pitfalls - ❌ Never output user-supplied HTML without running it through `htmlClean()` first - ✅ Use `"basic"` or `"basicWithImages"` for rich text editor output — `"relaxed"` is rarely safe for user input - ✅ `htmlParse()` is for trusted HTML you want to query; `htmlClean()` is for untrusted HTML you want to render - ❌ `doc.select()` uses CSS selectors, not XPath — `"#id"`, `".class"`, `"tag"`, `"[attr]"` syntax