{"id":20010107,"url":"https://github.com/cxa/xpaver","last_synced_at":"2025-05-04T19:36:01.118Z","repository":{"id":28098088,"uuid":"31596241","full_name":"cxa/XPaver","owner":"cxa","description":"Make XML navigation by XPath easier","archived":false,"fork":false,"pushed_at":"2019-10-15T13:45:22.000Z","size":146,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-20T10:08:07.851Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cxa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-03T12:02:36.000Z","updated_at":"2022-01-29T10:46:45.000Z","dependencies_parsed_at":"2022-09-02T19:01:04.408Z","dependency_job_id":null,"html_url":"https://github.com/cxa/XPaver","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxa%2FXPaver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxa%2FXPaver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxa%2FXPaver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cxa%2FXPaver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cxa","download_url":"https://codeload.github.com/cxa/XPaver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252390804,"owners_count":21740388,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T07:18:28.872Z","updated_at":"2025-05-04T19:36:00.721Z","avatar_url":"https://github.com/cxa.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XPaver\n\nMake XML navigation by XPath easier.\n\n## Install\n\nSwift package only. Add this repo url to your package dependencies. Xcode 11 supports by default.\n\n## Usage\n\n### Initialize a `Doc` first\n\n```swift\n  let xmlDoc = try! Doc(fileURL: assetURL(forName: \"xml.xml\"), kind: .xml)\n  // or if you want to use on HTML\n  let htmlDoc = try! Doc(fileURL: assetURL(forName: \"html.html\"), kind: .html)\n  // you can also init from data or string\n  let dataDoc = try! Doc(data: #\u003cdata\u003e, kind: .xml)\n  let stringDoc =  try! Doc(string: \"\u003chtml\u003e\u003cbody\u003eHello World\u003c/body\u003e\u003c/html\u003e\", kind: .html)\n```\n\n### Navigate by XPath\n\n```swift\n// func select(xpath: String) -\u003e [Node]\nlet nodes = htmlDoc.root.select(xpath: \"//p\") // Select all `p` on root node:\n\n// func first(xpath: String) -\u003e Node?\nlet p = htmlDoc.root.first(xpath: \"//p\")  // Select first `p` on root node:\nlet span = p.first(\"./span\")                 // Select first child span on `p`\n```\n\n### Evaluate XPath Expression\n\n```swift\nfunc eval(expr: String) -\u003e Node.EvalResult?\n\n// count how many p tags\nlet count = htmlDoc.root.eval(expr: \"count(//p)\")\n```\n\n### Node Info\n\n```swift\nvar tag: String?\nvar content: String?\nvar rawContent: String?\nvar innerRawContent: String?\nvar attributes: AnySequence\u003cNode.Attribute\u003e?\nfunc value(forAttribute name: String) -\u003e String?\n```\n\n### Node Hierarchies\n\n```swift\nvar parent: Node?\nvar childNodes: AnySequence\u003cNode\u003e?\nvar firstNode: Node?\nfunc childNode(at index: Int) -\u003e Node?\nvar prev: Node?\nvar next: Node?\n```\n\n### Advanced usage on namespace\n\nBy default, `XPaver` will solve namespaces for you internally, you don't need to care namespaces if document has only one default namespace.\n\nBut if you encounter a XML which contains more than one namespace like this:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?\u003e\n\u003cperson xmlns=\"http://www.your.example.com/xml/person\"\u003e\n  \u003cname\u003eRob\u003c/name\u003e\n  \u003cage\u003e37\u003c/age\u003e\n  \u003chomecity xmlns=\"http://www.my.example.com/xml/cities\"\u003e\n    \u003cname\u003eLondon\u003c/name\u003e\n    \u003clat\u003e123.000\u003c/lat\u003e\n    \u003clong\u003e0.00\u003c/long\u003e\n  \u003c/homecity\u003e\n\u003c/person\u003e\n```\n\nYou need to register namespaces and write namespaces in XPath directly:\n\n```swift\nlet mnsXmlDoc = try! Doc(fileURL: url, kind: .xml)\nmnsXmlDoc.register(namespaceURI: \"http://www.your.example.com/xml/person\", forPrefix: \"p\")\nmnsXmlDoc.register(namespaceURI: \"http://www.my.example.com/xml/cities\", forPrefix: \"c\")\nlet cityName = mnsXmlDoc.root.first(xpath: \"/p:person/c:homecity/c:name\")\n```\n\n## About Me\n\n- Twitter: [@\\_cxa](https://twitter.com/_cxa)\n- Apps available on the App Store: \u003chttp://lazyapps.com\u003e\n- PayPal: xianan.chen+paypal 📧 gmail.com, buy me a cup of coffee if you find this is useful for you\n\n## LICENSE\n\nMIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcxa%2Fxpaver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcxa%2Fxpaver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcxa%2Fxpaver/lists"}