Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@xml-tools/ast

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xml-tools/ast

XML Ast and Utilities

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
43K
increased by20.57%
Maintainers
1
Weekly downloads
 
Created
Source

npm (scoped)

@xml-tools/ast

Utilities for building and traversing an XML Abstract Syntax Tree (AST).

There are two things which distinguish this AST from most others ASTs:

  1. This AST can represent a partially valid XML, in practice this means virtually all properties on the AST are optional and may have undefined values.
  2. This AST contains additional syntactic information to enable additional linting & formatting flows, for example:
    • the original position and value of an attribute's value (including the quotes).
    • The original positions and values of an XMLElement's open/close names.

The input for constructing the AST is a CST which is created by the @xml-tools/parser package.

The AST structure is used as part of the input for the @xml-tools/content-assist APIs.

Installation

With npm:

  • npm install @xml-tools/ast

With Yarn

  • yarn add @xml-tools/ast

Usage

Please see the TypeScript Definitions for full API details.

A simple usage example:

const { parse } = require("xml-tools/parser");
const { buildAst, accept } = require("xml-tools/ast");

const xmlText = `<note>
                     <to>Bill</to>
                     <from>Tim</from>
                 </note>
`;

const { cst } = parse(xmlText);
const xmlDocAst = buildAst(cst);
console.log(xmlDocAst.rootElement.name); // -> note

// A Visitor allows us to invoke actions on the XML ASTNodes without worrying about
// The XML AST structure / traversal method.
const printVisitor = {
  // Will be invoked once for each Element node in the AST.
  visitXMLElement: function(node) {
    console.log(node.name);
  }

  // An XML AST Visitor may have other methods as well, see the api.d.ts file/
};

// Invoking the Visitor
accept(xmlDocAst, printVisitor); // -> note, Bill, Tim

Support

Please open issues on github.

Contributing

See CONTRIBUTING.md.

License

Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file.

Keywords

FAQs

Package last updated on 28 Oct 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc