# JavaScript XML libraries

JavaScript XML libraries parse XML documents into objects or DOM trees and write XML back out. A streaming parser emits an event for each tag rather than loading the whole document into memory. These libraries let apps read feeds, sitemaps, and SOAP responses from services that return XML.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [saxes](#saxes) | 617.8M | 86 | Nov 2021 | ISC |
| [sax](#sax) | 503.6M | 1.2K | Jul 2026 | BlueOak-1.0.0 |
| [fast-xml-parser](#fast-xml-parser) | 438.8M | 3.1K | Nov 2026 | MIT |
| [xmldom](#xmldom-xmldom) | 334.7M | 476 | Aug 2026 | MIT |
| [xml2js](#xml-js) | 243.7M | 5.0K | Jul 2023 | MIT |
| [xmlbuilder2](#xmlbuildertwo) | 65.0M | 410 | Dec 2025 | MIT |
| [xml-js](#xml-js-library) | 59.5M | 1.3K | Feb 2019 | MIT |
| [libxmljs2](#libxmljstwo) | 3.0M | 0 | Jun 2025 | MIT |

Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[saxes](#saxes) has the most monthly downloads in this comparison, at 617.8M.

## Capabilities

| Library | Incremental XML input | XML generation | XSD validation |
| --- | --- | --- | --- |
| [saxes](#saxes) | Yes | No | No |
| [sax](#sax) | Yes | No | No |
| [fast-xml-parser](#fast-xml-parser) | No | Yes | No |
| [xmldom](#xmldom-xmldom) | No | Yes | No |
| [xml2js](#xml-js) | No | Yes | No |
| [xmlbuilder2](#xmlbuildertwo) | No | Yes | No |
| [xml-js](#xml-js-library) | No | Yes | No |
| [libxmljs2](#libxmljstwo) | Yes | Yes | Yes |

## Libraries

### saxes

[GitHub](https://github.com/lddubeau/saxes) · [npm](https://www.npmjs.com/package/saxes) · [Docs](https://github.com/lddubeau/saxes/blob/master/README.md)

Parses XML as a stream of events.

- Downloads / mo: 617.8M
- Stars: 86
- Last release: 6.0.0
- License: ISC
- Capabilities: [From the saxes docs](https://github.com/lddubeau/saxes/blob/master/README.md)

```sh
npm install saxes
```

**Quickstart**

```javascript
const { SaxesParser } = require('saxes');

const parser = new SaxesParser({ xmlns: true });
parser.on('text', text => console.log(text));
parser.write('<root>Hello</root>').close();

```

From [README.md](https://github.com/lddubeau/saxes/blob/master/README.md) · [Find projects using saxes →](https://dashboard.exa.ai/playground/search?q=saxes%20GitHub%20projects)

### sax

[GitHub](https://github.com/isaacs/sax-js) · [npm](https://www.npmjs.com/package/sax) · [Docs](https://github.com/isaacs/sax-js/blob/main/README.md)

Emits events while it parses an XML stream.

- Downloads / mo: 503.6M
- Stars: 1.2K
- Last release: 1.6.1
- License: BlueOak-1.0.0
- Capabilities: [From the sax docs](https://github.com/isaacs/sax-js/blob/main/README.md)

```sh
npm install sax
```

**Leonidas-from-XIV/node-xml2js** (5.0K stars)

[Leonidas-from-XIV/node-xml2js](https://github.com/Leonidas-from-XIV/node-xml2js) 

```javascript
function() {
      var attrkey, charkey, ontext, stack;
      this.removeAllListeners();
      this.saxParser = sax.parser(this.options.strict, {
        trim: false,
        normalize: false,
        xmlns: this.options.xmlns
      });
      this.saxParser.errThrown = false;
      this.saxParser.onerror = (function(_this) {
        return function(error) {
          _this.saxParser.resume();
          if (!_this.saxParser.errThrown) {
            _this.saxParser.errThrown = true;
            return _this.emit("error", error);
          }
        };
      })(this);
      this.saxParser.onend = (function(_this) {
        return function() {
          if (!_this.saxParser.ended) {
            _this.saxParser.ended = true;
            return _this.emit("end", _this.resultObject);
          }
        };
      })(this);
      this.saxParser.ended = false;
      this.EXPLICIT_CHARKEY = this.options.explicitCharkey;
      this.resultObject = null;
      stack = [];
      attrkey = this.options.attrkey;
      charkey = this.options.charkey;
      this.saxParser.onopentag = (function(_this) {
        return function(node) {
          var key, newValue, obj, processedKey, ref;
          obj = {};
          obj[charkey] = "";
          if (!_this.options.ignoreAttrs) {
            ref = node.attributes;
            for (key in ref) {
              if (!hasProp.call(ref, key)) continue;
              if (!(attrkey in obj) && !_this.options.mergeAttrs) {
                obj[attrkey] = {};
              }
              newValue = _this.options.attrValueProcessors ? processItem(_this.options.attrValueProcessors, node.attributes[key], key) : node.attributes[key];
              processedKey = _this.options.attrNameProcessors ? processItem(_this.options.attrNameProcessors, key) : key;
              if (_this.options.mergeAttrs) {
                _this.assignOrPush(obj, processedKey, newValue);
              } else {
                defineProperty(obj[attrkey], processedKey, newValue);
              }
            }
          }
          obj["#name"] = _this.options.tagNameProcessors ? processItem(_this.options.tagNameProcessors, node.name) : node.name;
          if (_this.options.xmlns) {
            obj[_this.options.xmlnskey] = {
              uri: node.uri,
              local: node.local
            };
          }
          return stack.push(obj);
        };
      })(this);
      this.saxParser.onclosetag = (function(_this) {
        return function() {
          var cdata, emptyStr, key, node, nodeName, obj, objClone, old, s, xpath;
          obj = stack.pop();
          nodeName = obj["#name"];
          if (!_this.options.explicitChildren || !_this.options.preserveChildrenOrder) {
            delete obj["#name"];
          }
          if (obj.cdata === true) {
            cdata = obj.cdata;
            delete obj.cdata;
          }
          s = stack[stack.length - 1];
          if (obj[charkey].match(/^\s*$/) && !cdata) {
            emptyStr = obj[charkey];
            delete obj[charkey];
          } else {
            if (_this.options.trim) {
              obj[charkey] = obj[charkey].trim();
            }
            if (_this.options.normalize) {
              obj[charkey] = obj[charkey].replace(/\s{2,}/g, " ").trim();
            }
            obj[charkey] = _this.options.valueProcessors ? processItem(_this.options.valueProcessors, obj[charkey], nodeName) : obj[charkey];
            if (Object.keys(obj).length === 1 && charkey in obj && !_this.EXPLICIT_CHARKEY) {
              obj = obj[charkey];
            }
          }
          if (isEmpty(obj)) {
            if (typeof _this.options.emptyTag === 'function') {
              obj = _this.options.emptyTag();
            } else {
              obj = _this.options.emptyTag !== '' ? _this.options.emptyTag : emptyStr;
            }
          }
          if (_this.options.validator != null) {
            xpath = "/" + ((function() {
              var i, len, results;
              results = [];
              for (i = 0, len = stack.length; i < len; i++) {
                node = stack[i];
                results.push(node["#name"]);
              }
              return results;
            })()).concat(nodeName).join("/");
            (function() {
              var err;
              try {
                return obj = _this.options.validator(xpath, s && s[nodeName], obj);
              } catch (error1) {
                err = error1;
                return _this.emit("error", err);
              }
            })();
          }
          if (_this.options.explicitChildren && !_this.options.mergeAttrs && typeof obj === 'object') {
            if (!_this.options.preserveChildrenOrder) {
              node = {};
              if (_this.options.attrkey in obj) {
                node[_this.options.attrkey] = obj[_this.options.attrkey];
                delete obj[_this.options.attrkey];
              }
              if (!_this.options.charsAsChildren && _this.options.charkey in obj) {
                node[_this.options.charkey] = obj[_this.options.charkey];
                delete obj[_this.options.charkey];
              }
              if (Object.getOwnPropertyNames(obj).length > 0) {
                node[_this.options.childkey] = obj;
              }
              obj = node;
            } else if (s) {
              s[_this.options.childkey] = s[_this.options.childkey] || [];
              objClone = {};
              for (key in obj) {
                if (!hasProp.call(obj, key)) continue;
                defineProperty(objClone, key, obj[key]);
              }
              s[_this.options.childkey].push(objClone);
              delete obj["#name"];
              if (Object.keys(obj).length === 1 && charkey in obj && !_this.EXPLICIT_CHARKEY) {
                obj = obj[charkey];
              }
            }
          }
          if (stack.length > 0) {
            return _this.assignOrPush(s, nodeName, obj);
          } else {
            if (_this.options.explicitRoot) {
              old = obj;
              obj = {};
              defineProperty(obj, nodeName, old);
            }
            _this.resultObject = obj;
            _this.saxParser.ended = true;
            return _this.emit("end", _this.resultObject);
          }
        };
      })(this);
      ontext = (function(_this) {
        return function(text) {
          var charChild, s;
          s = stack[stack.length - 1];
          if (s) {
            s[charkey] += text;
            if (_this.options.explicitChildren && _this.options.preserveChildrenOrder && _this.options.charsAsChildren && (_this.options.includeWhiteChars || text.replace(/\\n/g, '').trim() !== '')) {
              s[_this.options.childkey] = s[_this.options.childkey] || [];
              charChild = {
                '#name': '__text__'
              };
              charChild[charkey] = text;
              if (_this.options.normalize) {
                charChild[charkey] = charChild[charkey].replace(/\s{2,}/g, " ").trim();
              }
              s[_this.options.childkey].push(charChild);
            }
            return s;
          }
        };
      })(this);
      this.saxParser.ontext = ontext;
      return this.saxParser.oncdata = (function(_this) {
        return function(text) {
          var s;
          s = ontext(text);
          if (s) {
            return s.cdata = true;
          }
        };
      })(this);
    }

```

[lib/parser.js](https://github.com/Leonidas-from-XIV/node-xml2js/blob/7173c245aab4c2b417cd4c24f0b54e697a369864/lib/parser.js#L119-L311) · [More projects using sax →](https://dashboard.exa.ai/playground/search?q=sax%20GitHub%20projects)

**Quickstart**

```javascript
const sax = require('sax');

const parser = sax.parser(true);
parser.ontext = text => console.log(text);
parser.write('<root>Hello</root>').close();

```

From [README.md](https://github.com/isaacs/sax-js/blob/main/README.md)

### fast-xml-parser

[GitHub](https://github.com/NaturalIntelligence/fast-xml-parser) · [npm](https://www.npmjs.com/package/fast-xml-parser) · [Docs](https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/README.md)

Parses XML into JavaScript objects and builds XML through a configurable JavaScript API.

- Downloads / mo: 438.8M
- Stars: 3.1K
- Last release: 5.12.1
- License: MIT
- Capabilities: [From the fast-xml-parser docs](https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/README.md)

**Strengths**

- **Controls which tags become arrays.** Use isArray to give selected XML elements a consistent shape.
- **Preserves tag order when configured.** Enable preserveOrder when XML content order matters.

**Watch out for**

- **Attributes are ignored by default.** Set ignoreAttributes:false when attributes are part of the data.
- **Syntax validation is opt-in.** Pass true to parse or call XMLValidator explicitly.

```sh
npm install fast-xml-parser
```

**jhipster/generator-jhipster** (22.5K stars)

[jhipster/generator-jhipster](https://github.com/jhipster/generator-jhipster) 

```typescript
export const sortPomFile = (pomFile: string, { xmlParserOptions, xmlBuildOptions }: SortPomFileOptions = {}): string => {
  const parser = new XMLParser({ ...defaultXmlParserOptions, ...xmlParserOptions });
  const pomObject = parser.parse(pomFile);
  pomObject.project = sortPomProject(pomObject.project);

  const builder = new FastXmlBuilder({ ...defaultXmlBuildOptions, ...xmlBuildOptions });
  return formatPomFirstLevel(builder.build(pomObject));
};

```

[generators/java-simple-application/generators/maven/support/pom-file-sort.ts](https://github.com/jhipster/generator-jhipster/blob/761fcb688c9dacc6d2559f76f14518f22f26515f/generators/java-simple-application/generators/maven/support/pom-file-sort.ts#L27-L34) · [More projects using fast-xml-parser →](https://dashboard.exa.ai/playground/search?q=JavaScript%20applications%20using%20fast-xml-parser%20for%20XML%20parsing%2C%20document%20editing%2C%20serialization%2C%20XPath%20or%20schema%20validation&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```typescript
const { XMLParser } = require('fast-xml-parser');

const parser = new XMLParser();
const result = parser.parse('<root>text</root>');

```

From [README.md](https://cdn.jsdelivr.net/npm/fast-xml-parser@5.12.1/src/fxp.d.ts)

### xmldom

[GitHub](https://github.com/xmldom/xmldom) · [npm](https://www.npmjs.com/package/@xmldom/xmldom) · [Docs](https://github.com/xmldom/xmldom/blob/0af8cf829d8a92bbac612903422c6947f5458f06/readme.md)

Provides JavaScript XML DOM parsing, document-tree editing, and XML serialization.

- Downloads / mo: 334.7M
- Stars: 476
- Last release: 0.9.12
- License: MIT
- Capabilities: [From the xmldom docs](https://github.com/xmldom/xmldom/blob/0af8cf829d8a92bbac612903422c6947f5458f06/readme.md)

**Strengths**

- **Edits DOM nodes directly.** Create elements, update attributes, and change the document tree.
- **Serializes DOM trees to XML.** Convert edited documents back to strings with XMLSerializer.

**Watch out for**

- **XPath integration uses another package.** Pair xpath, a path-query library, with the parsed DOM.
- **Browser DOM compatibility is partial.** Check required browser APIs before sharing DOM-dependent code with Node.

```sh
npm install @xmldom/xmldom
```

**appium/appium** (22.2K stars)

[appium/appium](https://github.com/appium/appium) 

```typescript
export function runQuery(query: string, xmlStr: string): Element[] {
  const dom = new DOMParser().parseFromString(xmlStr, MIME_TYPE.XML_TEXT);
  let nodes: ReturnType<typeof xpathQuery>;
  try {
    // @ts-expect-error Missing Node properties are not needed.
    // https://github.com/xmldom/xmldom/issues/724
    nodes = xpathQuery(query, dom);
  } catch (err) {
    // report a malformed query the same way drivers do instead of as an unknown server error.
    // messages such as 'Unknown function foo' tell the user what to fix, the generic one does not
    const reason = (err as Error).message;
    const details = reason && reason !== GENERIC_XPATH_PARSE_ERROR ? ` (${reason})` : '';
    throw new errors.InvalidSelectorError(`Invalid XPath selector: ${query}${details}`, err as Error);
  }
  // the xpath typings describe lib.dom nodes rather than xmldom ones, so this is the one place
  // where the two type worlds have to be bridged
  return nodes as unknown as Element[];
}

```

[packages/universal-xml-plugin/lib/xpath.ts](https://github.com/appium/appium/blob/4f9fe0544297564a96c1210141c1f0532b609b1c/packages/universal-xml-plugin/lib/xpath.ts#L14-L31) · [More projects using xmldom →](https://dashboard.exa.ai/playground/search?q=JavaScript%20applications%20using%20%40xmldom/xmldom%20for%20XML%20parsing%2C%20document%20editing%2C%20serialization%2C%20XPath%20or%20schema%20validation&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```typescript
const { DOMParser, MIME_TYPE } = require('@xmldom/xmldom');

const document = new DOMParser().parseFromString('<root/>', MIME_TYPE.XML_TEXT);

```

From [readme.md](https://cdn.jsdelivr.net/npm/@xmldom/xmldom@0.9.12/index.d.ts)

### xml2js

[GitHub](https://github.com/Leonidas-from-XIV/node-xml2js) · [npm](https://www.npmjs.com/package/xml2js) · [Docs](https://github.com/Leonidas-from-XIV/node-xml2js/blob/master/README.md)

Maps XML to JavaScript objects and builds XML from object data.

- Downloads / mo: 243.7M
- Stars: 5.0K
- Last release: 0.6.2
- License: MIT
- Capabilities: [From the xml2js docs](https://github.com/Leonidas-from-XIV/node-xml2js/blob/master/README.md)

**Strengths**

- **Offers promise-based parsing.** Use parseStringPromise in asynchronous XML loading workflows.
- **Builds attributes and text together.** Use the object’s attribute and text keys when rebuilding XML.

**Watch out for**

- **Round trips depend on settings.** Keep defaults when exact object-to-XML round trips matter.
- **Parser reuse needs a reset.** Create one parser per file or reset it between documents.

```sh
npm install xml2js
```

**lingodotdev/lingo.dev** (5.4K stars)

[lingodotdev/lingo.dev](https://github.com/lingodotdev/lingo.dev) 

```typescript
export default function createXmlLoader(): ILoader<
  string,
  Record<string, any>
> {
  return createLoader({
    async pull(locale, input) {
      let result: Record<string, any> = {};

      try {
        const parsed = await parseStringPromise(input, {
          explicitArray: false,
          mergeAttrs: false,
          normalize: true,
          preserveChildrenOrder: true,
          normalizeTags: true,
          includeWhiteChars: true,
          trim: true,
        });
        result = parsed;
      } catch (error) {
        console.error("Failed to parse XML:", error);
        result = {};
      }

      return result;
    },

    async push(locale, data) {
      try {
        const builder = new Builder({ headless: true });
        const xmlOutput = builder.buildObject(data);
        const expectedOutput = normalizeXMLString(xmlOutput);
        return expectedOutput;
      } catch (error) {
        console.error("Failed to build XML:", error);
        return "";
      }
    },
  });
}

```

[packages/cli/src/cli/loaders/xml.ts](https://github.com/lingodotdev/lingo.dev/blob/fbc666cf717bbe80a57ce49b8d0fce690ee1766f/packages/cli/src/cli/loaders/xml.ts#L12-L51) · [More projects using xml2js →](https://dashboard.exa.ai/playground/search?q=JavaScript%20applications%20using%20xml2js%20for%20XML%20parsing%2C%20document%20editing%2C%20serialization%2C%20XPath%20or%20schema%20validation&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```typescript
import xml2js from 'xml2js';

const result = await xml2js.parseStringPromise('<root>text</root>');

```

From [README.md](https://github.com/Leonidas-from-XIV/node-xml2js/blob/master/README.md)

### xmlbuilder2

[GitHub](https://github.com/oozcitak/xmlbuilder2) · [npm](https://www.npmjs.com/package/xmlbuilder2) · [Docs](https://github.com/oozcitak/xmlbuilder2/blob/master/README.md)

Builds XML documents in Node.js.

- Downloads / mo: 65.0M
- Stars: 410
- Last release: 4.0.3
- License: MIT
- Capabilities: [From the xmlbuilder2 docs](https://github.com/oozcitak/xmlbuilder2/blob/master/README.md)

```sh
npm install xmlbuilder2
```

**projen/projen** (3.0K stars)

[projen/projen](https://github.com/projen/projen) 

```javascript
protected synthesizeContent(resolver: IResolver): string | undefined {
    const obj = super.synthesizeContent(resolver);
    if (!obj) {
      return undefined;
    }

    const xmlString = createxml({ encoding: "UTF-8" }, obj).end({
      prettyPrint: true,
      indent: " ".repeat(4),
    });

    return [
      xmlString,
      ...(this.marker ? [`<!-- ${this.marker} -->`] : []),
    ].join("\n");
  }

```

[src/xmlfile.ts](https://github.com/projen/projen/blob/8184f0234e05442df0c0491237b08815770bf48a/src/xmlfile.ts#L27-L42) · [More projects using xmlbuilder2 →](https://dashboard.exa.ai/playground/search?q=xmlbuilder2%20GitHub%20projects)

**Quickstart**

```javascript
const { create } = require('xmlbuilder2');

const document = create().ele('root').txt('text');
const xml = document.end({ prettyPrint: true });

```

From [BuilderFunctions.d.ts](https://cdn.jsdelivr.net/npm/xmlbuilder2@4.0.3/lib/builder/BuilderFunctions.d.ts)

### xml-js

[GitHub](https://github.com/nashwaan/xml-js) · [npm](https://www.npmjs.com/package/xml-js) · [Docs](https://github.com/nashwaan/xml-js/blob/master/README.md)

Converts between XML text and JavaScript objects or JSON.

- Downloads / mo: 59.5M
- Stars: 1.3K
- Last release: 1.6.11
- License: MIT
- Capabilities: [From the xml-js docs](https://github.com/nashwaan/xml-js/blob/master/README.md)

```sh
npm install xml-js
```

**niklashigi/apk-mitm** (5.1K stars)

[niklashigi/apk-mitm](https://github.com/niklashigi/apk-mitm) 

```javascript
export default async function modifyManifest(
  path: string,
  debuggable = false,
  mapsApiKey = '',
) {
  const document = xml.xml2js(await fs.readFile(path, 'utf-8')) as xml.Element

  const manifest = document.elements?.find(el => el.name === 'manifest')!
  const application = manifest.elements?.find(el => el.name === 'application')!

  application.attributes = {
    ...application.attributes,

    // Configure app to use custom Network Security Config
    'android:networkSecurityConfig': '@xml/nsc_mitm',

    // Make app debuggable when `--debuggable` flag is used
    ...(debuggable && { 'android:debuggable': 'true' }),
  }

  const usesAppBundle =
    application.elements?.some(
      el =>
        el.name === 'meta-data' &&
        el.attributes?.['android:name'] === 'com.android.vending.splits',
    ) ?? false

  if (mapsApiKey) {
    application.elements?.forEach(el => {
      if (el.name === 'meta-data') {
        const name = el.attributes?.['android:name'] + ''
        const mapsApiName = [
          'com.google.android.maps.v2.API_KEY',
          'com.google.android.geo.API_KEY',
        ]
        if (mapsApiName.includes(name)) {
          el.attributes!['android:value'] = mapsApiKey
        }
      }
    })
  }

  await fs.writeFile(path, xml.js2xml(document, { spaces: 4 }))

  return { usesAppBundle }
}

```

[src/tasks/modify-manifest.ts](https://github.com/niklashigi/apk-mitm/blob/5a96363fc9112b97d60fc2bd3799d6bbfd8e4e00/src/tasks/modify-manifest.ts#L4-L49) · [More projects using xml-js →](https://dashboard.exa.ai/playground/search?q=xml-js%20GitHub%20projects)

**Quickstart**

```javascript
const convert = require('xml-js');

const document = convert.xml2js('<root>text</root>');

```

From [index.d.ts](https://cdn.jsdelivr.net/npm/xml-js@1.6.11/types/index.d.ts)

### libxmljs2

[GitHub](https://github.com/marudor/libxmljs2) · [npm](https://www.npmjs.com/package/libxmljs2) · [Docs](https://github.com/marudor/libxmljs2/blob/main/README.md)

Provides libxml bindings for JavaScript.

- Downloads / mo: 3.0M
- Stars: 0
- Last release: 0.37.0
- License: MIT
- Capabilities: [From the libxmljs2 docs](https://github.com/marudor/libxmljs2/blob/main/README.md)

```sh
npm install libxmljs2
```

**nfewizard-org/nfewizard-io** (327 stars)

[nfewizard-org/nfewizard-io](https://github.com/nfewizard-org/nfewizard-io) 

```javascript
function runJsBased(xml: string, metodo: SchemaValidateMethod): Promise<SchemaValidationResult> {
    return new Promise(async (resolve, reject) => {
        const { basePath, schemaPath } = getSchema(metodo);
        if (!schemaPath) {
            reject(makeResult(false, metodo, '', [internalIssue(
                `Schema XSD não encontrado para o método '${metodo}'. Verifique se o nome do método está correto.`,
            )]));
            return;
        }

        try {
            const completeXSD = await xsdAssembler.assemble(schemaPath);
            const xmlDoc = libxmljs.parseXml(xml);
            const xsdDoc = libxmljs.parseXml(completeXSD, { baseUrl: `${basePath}/` });

            const isValid = xmlDoc.validate(xsdDoc);
            if (isValid) {
                resolve(makeResult(true, metodo, schemaPath, []));
                return;
            }

            const errors: SchemaValidationIssue[] = (xmlDoc.validationErrors || []).map((e: any) =>
                humanizeIssue(String(e.message ?? e).trim(), e.line, e.column),
            );
            reject(makeResult(false, metodo, schemaPath, errors.length ? errors : [internalIssue('XML inválido (sem detalhes do validador).')]));
        } catch (error: any) {
            reject(makeResult(false, metodo, schemaPath, [internalIssue(String(error?.message ?? error))]));
        }
    });
}

```

[packages/shared/src/utils/validateSchema.ts](https://github.com/nfewizard-org/nfewizard-io/blob/dd7d9e692f9cec5644f992d9123caf6721843e73/packages/shared/src/utils/validateSchema.ts#L254-L283) · [More projects using libxmljs2 →](https://dashboard.exa.ai/playground/search?q=libxmljs2%20GitHub%20projects)

**Quickstart**

```javascript
const libxml = require('libxmljs2');

const document = libxml.parseXml('<root/>');

```

From [index.d.ts](https://cdn.jsdelivr.net/npm/libxmljs2@0.37.0/index.d.ts)

## FAQ

### Which JavaScript XML library should I use?

[fast-xml-parser](#fast-xml-parser) suits converting XML to JavaScript objects and back. [xmldom](#xmldom-xmldom) suits code that needs a standard DOM to query and edit. [saxes](#saxes) suits large documents that must stream.

### What is fast-xml-parser?

[fast-xml-parser](#fast-xml-parser) parses XML into JavaScript objects and builds XML from objects. Its options control attributes, arrays, and value parsing.

### What is xml2js?

[xml2js](#xml-js) maps XML to JavaScript objects and builds XML from object data. It wraps the sax parser in a callback and promise API.

### How do I convert XML to JSON in JavaScript?

Parse the XML into a JavaScript object with [fast-xml-parser](#fast-xml-parser) or [xml-js](#xml-js-library), then pass the object to JSON.stringify.

### What is a SAX parser?

A SAX parser reads XML as a stream and emits an event for each opening tag, text node, and closing tag. [sax](#sax) and [saxes](#saxes) use this model for documents too large to hold in memory.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best JavaScript XML libraries fast-xml-parser xml2js xmldom libxml2-wasm code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
