{"id":19467876,"url":"https://github.com/pgooood/php-xml-lib","last_synced_at":"2025-10-18T21:10:14.941Z","repository":{"id":219276751,"uuid":"94881429","full_name":"pgooood/php-xml-lib","owner":"pgooood","description":"Handy wrapper for the PHP DOM, XPath and XSLTProcessor","archived":false,"fork":false,"pushed_at":"2022-04-25T08:19:07.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-08T04:36:27.814Z","etag":null,"topics":["dom","php-dom","xml","xpath","xslt"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/pgooood.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-06-20T10:55:43.000Z","updated_at":"2022-04-25T08:19:10.000Z","dependencies_parsed_at":"2024-01-26T13:47:07.816Z","dependency_job_id":"965d0705-a0c1-4752-b84d-98282fc03639","html_url":"https://github.com/pgooood/php-xml-lib","commit_stats":null,"previous_names":["pgooood/php-xml-lib"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgooood%2Fphp-xml-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgooood%2Fphp-xml-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgooood%2Fphp-xml-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgooood%2Fphp-xml-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pgooood","download_url":"https://codeload.github.com/pgooood/php-xml-lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240681163,"owners_count":19840317,"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":["dom","php-dom","xml","xpath","xslt"],"created_at":"2024-11-10T18:37:15.164Z","updated_at":"2025-10-18T21:10:09.909Z","avatar_url":"https://github.com/pgooood.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP XML lib\nHandy wrapper for the PHP DOM, XPath and XSLTProcessor \n\nManual is under construction.\n\nExamples\n-------\n```php\n$xml = new \\pgood\\xml\\xml('demo.xml');\n\n//get string value (xpath)\n$title = $xml-\u003eevaluate('string(/catalog/book[@id=\"bk103\"]/title)');\n\n//get dom element (xpath)\n$element = $xml-\u003equery('//book[2]')-\u003eitem(0);\n\n//get subelement value (xpath)\n$price = $element-\u003eevaluate('number(price)');\n//or\n$price = $xml-\u003eevaluate('number(price)',$element);\n\n//get attribute\n$oldId = $element-\u003eid;\n//or\n$oldId = $element-\u003egetAttribute('id');\n\n//remove attribute\n$element-\u003eid = null;\n//or\n$element-\u003eremoveAttribute('id');\n\n//set attribute\n$element-\u003eid = 'newId';\n//or\n$element-\u003esetAttribute('id','newId');\n\n//set text content\n$element-\u003etext('new text content');\n\n//get text content\n$element-\u003etext();\n\n//append new element\n$newElem = $element-\u003eappend('new-element');\n\n//move queryed element before \n$newElem-\u003ebefore($xml-\u003equery('//book[3]')-\u003eitem(0));\n\n//move queryed element after new one\n$newElem-\u003eafter($xml-\u003equery('//book[1]')-\u003eitem(0));\n\n//get previous element\n$newElem-\u003eprev();\n\n//get next element\n$newElem-\u003enext();\n\n//get DOMElement object\n$newElem-\u003ee();\n\n//get parent\n$newElem-\u003eparent();\n\n//remove element\n$newElem-\u003eremove();\n\n//save changes\n$xml-\u003esave();\n\n//get PHP DOMDocument\n$dd = $xml-\u003edd();\n\n//get root element\n$documentElement = $xml-\u003ede();\n\n/*\n * XSLT Transformation\n */\n$tpl = new \\pgood\\xml\\template('tpl.xsl');\necho $tpl-\u003etransform($xml);\n\n/*\n * XML from scratch\n */\n$xml = new \\pgood\\xml\\xml();\n$xml-\u003ede('root-element-name');\n\n//using the xml::create method for element creation\n$newElement1 = $xml-\u003ede()-\u003eappend($xml-\u003ecreate(\n\t\t'child-element-tag-name'\n\t\t,array(\n\t\t\t'attr-name-1' =\u003e 'value for first attribute'\n\t\t\t,'attr-name-2' =\u003e 'value for second attribute'\n\t\t)\n\t\t,'element text content'\n\t));\n\n//lazy element creation\n$newElement2 = $xml-\u003ede()-\u003eappend('child-element-tag-name');\n$newElement2-\u003e{'element-id'} = 'id value';\n\n//catch up an existed DOMDocument\n$xml2 = new \\pgood\\xml\\xml($newElement2);\n\n//new XML from inline code\n$xml = new \\pgood\\xml\\xml('\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\u003cdata\u003econtent\u003c/data\u003e');\n\n//parse HTML\n$xml-\u003eloadHTML('\u003chtml\u003e\u003chead\u003e\u003ctile\u003eHello World!\u003c/title\u003e\u003c/head\u003e\u003cbody\u003e\u003ch1\u003eHello World!\u003c/h1\u003e\u003c/body\u003e\u003c/html\u003e');\n\n//save\n$xml-\u003esave('new-file-name.xml');\n\n/*\n * XPath and namespace\n * Let's count media:content elements in Yahoo RSS feed\n */\n$xml = new \\pgood\\xml\\xml('https://www.yahoo.com/news/rss/');\n$xml-\u003eregisterNameSpace('media','http://search.yahoo.com/mrss/');\n$numElemets = $xml-\u003eevaluate('count(//media:content)');\n```\n\ndemo.xml\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003ccatalog\u003e\n\t\u003cbook id=\"bk101\"\u003e\n\t\t\u003cauthor\u003eGambardella, Matthew\u003c/author\u003e\n\t\t\u003ctitle\u003eXML Developer's Guide\u003c/title\u003e\n\t\t\u003cgenre\u003eComputer\u003c/genre\u003e\n\t\t\u003cprice\u003e44.95\u003c/price\u003e\n\t\t\u003cpublish_date\u003e2000-10-01\u003c/publish_date\u003e\n\t\t\u003cdescription\u003eAn in-depth look at creating applications with XML.\u003c/description\u003e\n\t\u003c/book\u003e\n\t\u003cbook id=\"bk102\"\u003e\n\t\t\u003cauthor\u003eRalls, Kim\u003c/author\u003e\n\t\t\u003ctitle\u003eMidnight Rain\u003c/title\u003e\n\t\t\u003cgenre\u003eFantasy\u003c/genre\u003e\n\t\t\u003cprice\u003e5.95\u003c/price\u003e\n\t\t\u003cpublish_date\u003e2000-12-16\u003c/publish_date\u003e\n\t\t\u003cdescription\u003eA former architect battles corporate zombies, an evil sorceress, and her own childhood to become queen of the world.\u003c/description\u003e\n\t\u003c/book\u003e\n\t\u003c!-- ... --\u003e\n\u003c/catalog\u003e\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgooood%2Fphp-xml-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpgooood%2Fphp-xml-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgooood%2Fphp-xml-lib/lists"}