Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@office-open/xml

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@office-open/xml

XML parsing and serialization for Office Open XML. Zero dependencies, drop-in replacement for xml + xml-js.

edge
latest
Source
npmnpm
Version
0.9.0
Version published
Weekly downloads
744
-63.39%
Maintainers
1
Weekly downloads
 
Created
Source

@office-open/xml

npm version npm downloads npm license zero dependencies

XML parsing and serialization for Office Open XML. Zero dependencies, drop-in replacement for xml + xml-js.

Features

  • Zero Dependencies - No external runtime dependencies, pure TypeScript implementation
  • xml() Serialization - Drop-in replacement for the xml package
  • xml2js() Parsing - Drop-in replacement for xml-js XML parsing
  • js2xml() Stringifying - Drop-in replacement for xml-js JS-to-XML conversion
  • toElement() Direct Convert - Direct conversion from xml object format to xml-js Element, 10-19x faster than the xml→xml2js bridge
  • Complete Type Definitions - Full type compatibility with xml and xml-js, import without changes
  • OOXML Optimized - Implements all options needed for Office Open XML document generation

Installation

# pnpm
pnpm add @office-open/xml

# npm
npm install @office-open/xml

# yarn
yarn add @office-open/xml

# bun
bun add @office-open/xml

Migration from xml + xml-js

Replace your existing imports:

// Before
import xml from "xml";
import { xml2js, js2xml } from "xml-js";
import type { Element } from "xml-js";

// After
import { xml, xml2js, js2xml } from "@office-open/xml";
import type { Element } from "@office-open/xml";

No other code changes needed. All options and output formats are compatible.

Quick Start

import { xml, xml2js, js2xml, toElement } from "@office-open/xml";

// Serialize JS objects to XML
const xmlStr = xml({ "w:p": [{ _attr: { "w:val": "1" } }, { "w:r": [{ "w:t": "Hello" }] }] });
// <w:p w:val="1"><w:r><w:t>Hello</w:t></w:r></w:p>

// Parse XML to JS objects
const parsed = xml2js("<w:t>Hello</w:t>", { compact: false });

// Convert JS objects back to XML
const output = js2xml(parsed);

// Direct conversion (faster than xml → xml2js bridge)
const element = toElement({
  "w:p": [{ _attr: { "w:val": "1" } }, { "w:r": [{ "w:t": "Hello" }] }],
});

API

xml(input, options?)

Serialize JavaScript objects to XML string. Compatible with the xml package.

xml2js(xmlString, options?)

Parse XML string to JavaScript object. Compatible with xml-js.

js2xml(jsObject, options?)

Convert JavaScript object (xml-js Element format) to XML string. Compatible with xml-js.

json2xml(jsObject, options?)

Alias for js2xml.

xml2json(xmlString, options?)

Convenience function that returns JSON.stringify(xml2js(xmlString, options)).

toElement(input)

Direct conversion from xml object format to xml-js Element format. Much faster than the xml() → xml2js() bridge path.

escapeXml(str) / escapeAttributeValue(str)

Low-level XML entity escaping functions.

Benchmark

Performance comparison against original xml (1.0.1) and xml-js (1.6.11) packages:

Serialization (xml)

Scenario@office-open/xmlxmlSpeedup
Simple element5,069,751 hz724,533 hz7.00x
Nested element1,122,376 hz279,423 hz4.02x
Nested with declaration1,050,046 hz248,678 hz4.22x

Parsing (xml2js)

Scenario@office-open/xmlxml-jsSpeedup
Simple XML1,000,869 hz90,488 hz11.06x
Complex OOXML310,266 hz42,938 hz7.23x
With captureSpaces313,183 hz41,814 hz7.49x

Stringifying (js2xml)

Scenario@office-open/xmlxml-jsSpeedup
Simple element975,878 hz198,953 hz4.90x
Complex OOXML492,220 hz107,815 hz4.57x

Direct Conversion (toElement vs bridge)

ScenariotoElement()xml() + xml2js() bridgeSpeedup
Simple13,199,415 hz805,104 hz16.40x
Nested4,207,319 hz458,333 hz9.18x

Bundle Size

@office-open/xmlxml + xml-js
gzip4.22 kB~15 kB

License

  • MIT © Demo Macro

Keywords

office-open

FAQs

Package last updated on 12 Jun 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts