npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@openxmldev/linq-to-ooxml

v0.10.0

Published

OOXML Namespace-related Classes for LINQ to XML for TypeScript

Downloads

5

Readme

OOXML Namespace-Related Classes for LINQ to XML for TypeScript

codecov npm version

Office Open XML (also informally known as OOXML) was initially standardized by the Ecma (as ECMA-376), and by the ISO and IEC (as ISO/IEC 29500) in later versions. OOXML consists of:

  • a family of XML schemas, which define the XML vocabularies for word-processing, spreadsheet, and presentation documents; as well as
  • the packaging of documents that conform to these schemas.

The XML schemas define sets of XML element and attribute names, which are organized in XML namespaces.

In .NET, the Open XML SDK provides tools for working with Office Open XML, including XML namespace-related classes for LINQ to XML. This repo provides TypeScript classes (e.g., W, X, P) for relevant XML namespaces and the XML names contained in such namespaces. The namespace-related classes can be used with the @openxmldev/linq-to-xml library, which provides an implementation of LINQ to XML in TypeScript.

Installing

Run npm install @openxmldev/linq-to-ooxml to install the library.

Documentation

Building

Run nx build linq-to-ooxml to build the library.

Running Unit Tests

Run nx test linq-to-ooxml to execute the unit tests via Jest.

Examples

In short words, usage is identical to .NET. Have a look at the API documentation to see what is on offer.

Importing

Simply import the namespace-related classes from @openxmldev/linq-to-ooxml. For example:

import { W, W14, WP, WPC } from '@openxmldev/linq-to-ooxml';

All class names are the uppercase versions (e.g., W, W14, WP, WPC) of the namespace prefixes (e.g., w, w14, wp, wpc).

Properties Provided by the Namespace-related Classes

The following code snippet explains the anatomy of the namespace-related classes, using an excerpt of the W class. Firstly, with the exception of the NoNamespace class, each class declares exactly one property of type XNamespace, using the namespace prefix as the name of such property. In this case, the prefix is w, so the property is called w as well. Second, each class defines a getter called namespaceDeclaration, which returns an XAttribute representing an XML namespace declaration such as xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main". Again, the NoNamespace class is the exception because it does not represent a namespace but rather defines all names that do not have a namespace.

class W {
  public static readonly w: XNamespace = XNamespace.get(
    'http://schemas.openxmlformats.org/wordprocessingml/2006/main'
  );

  public static get namespaceDeclaration(): XAttribute {
    return new XAttribute(XNamespace.xmlns.getName('w'), W.w.namespaceName);
  }

  public static readonly document: XName = W.w.getName('document');
  public static readonly body: XName = W.w.getName('body');
  public static readonly p: XName = W.w.getName('p');
  public static readonly r: XName = W.w.getName('r');
  public static readonly t: XName = W.w.getName('t');
}

Third, each class defines properties for all names (e.g., w:document, w:body, w:p) defined in the namespace (or having no namespace in the case of the NoNamespace class).

Using the Namespace-related Classes

Using the names in conjunction with the classes provided by the @openxmldev/linq-to-xml package, you could create a super-simple "Hello World!" document as follows:

const document =
  new XElement(W.document,
    W.namespaceDeclaration,
    new XElement(W.body,
      new XElement(W.p,
        new XElement(W.r,
          new XElement(W.t, 'Hello World!')))));

Language-specific Differences

The reserved keywords in C# and TypeScript are different, meaning that there are some minor differences in the naming of the static properties in C# vs. TypeScript.

In C#, the @ character is prepended where a property name is a reserved keyword. In case the property name does not collide with a reserved keyword in TypeScript, the property name is used as-is.

In TypeScript, collisions with reserved keywords or names are resolved by appending underscores to property names. For example, name and length are reserved names in TypeScript, meaning an underscore will be appended in those two cases.