# xml-utils > The lightest XML parsing library ## features - Only import the functions that you need - No external dependencies - Runs the same in NodeJS and Browser - Supports TypeScript ## install ```bash npm install xml-utils ``` # usage ## the simple tag object XML tags are represented by a simple object with an outer and inner property. The "outer" property is the text string that completely encompasses the tag, equivalent to an HTML element's "outerHTML". The "inner" property represents the sub-parts of the tag. It is similar to an HTML element's "textContent". Here's an example of a tag: ```javascript { outer: "PIXEL", inner: "PIXEL" } ``` ## get attribute ```javascript const getAttribute = require("xml-utils/get-attribute.js"); const xml = `PIXEL`; const key = getAttribute(xml, "key"); // key is "INTERLEAVE" ``` ## find one tag by name ```javascript const findTagByName = require("xml-utils/find-tag-by-name.js"); const xml = `PIXEL` const tag = findTagByName(xml, "MDI"); ``` tag is ```javascript { outer: "PIXEL", inner: "PIXEL" } ``` ## find multiple tags with the same name ```javascript const findTagsByName = require("xml-utils/find-tags-by-name.js"); const xml = ` 1 255 96.372431147996 0 50.057898474622 `; const tags = findTagsByName(xml, "MDI"); // tags is an array of tags ``` ## find one tag by path ```javascript const findTagByPath = require("xml-utils/find-tag-by-path.js"); const xml = ` 4326 EPSG 6.11 `; const tag = findTagByPath(xml, ["gmd:RS_Identifier", "gmd:code", "gco:CharacterString"]); ``` ## find multiple tags by path To get an array of tags that follow a path: ```javascript const findTagsByPath = require("xml-utils/find-tags-by-path.js"); const tags = findTagByPath(xml, ["Metadata", "MDI"]); // tags is an array of tags ``` ## remove comments ```javascript const removeComments = require("xml-utils/remove-comments.js"); const xml = ` `; removeComments(xml); "\n \n"; ``` ## remove tags by name ```js const removeTagsByName = require("xml-utils/remove-tags-by-name.js"); const xml = "
  • A
  • B
"; removeTagsByName(xml, "li") "
    " ``` ## setup download test files with: ```bash npm run setup ``` ## test ```bash npm run test ``` # contact Post an issue at https://github.com/DanielJDufour/xml-utils/issues or email the package author at daniel.j.dufour@gmail.com