New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

get-doctype

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-doctype

Javascript module for parsing doctypes in XML document

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-88.24%
Maintainers
1
Weekly downloads
 
Created
Source

get-doctype

Javascript module for parsing doctypes in XML document. Useful to get name, pubid and sysid whithout parsing the whole XML document Make usage of existing module :

  • saxjs for SAX parsing XML document (https://github.com/isaacs/sax-js)
  • piece of code of "xmldom" for splitting doctype into correc parts (https://github.com/jindw/xmldom, split function of sax.js file)

Usage

From command line

Readin a file from its path :

./parse-doctype test/dataset/public.xml 

Output looks like this :

{ type: 'PUBLIC',
  name: 'TEI.2',
  pubid: '-//TEI P4//DTD Main DTD Driver File//EN',
  sysid: 'http://www.tei-c.org/Lite/DTD/teixlite.dtd' }

Reading stdin :

cat test/dataset/public.xml | ./parse-doctype

If no doctype found or error while parsing file, then an error is thrown.

./parse-doctype test/dataset/no-doctype.xml
[Error: No doctype found]

./parse-doctype test/dataset/parsing-problem.xml 
[Error: No doctype found, Sax-Error: Unexpected end
Line: 0
Column: 180
Char: ]

From a javascript / nodejs program

Readin a file from its path :

var getDoctype = require("get-doctype");
var xmlFile = "test/dataset/public.xml";
getDoctype.parseFile(xmlFile, function(doctype) {
  // Do what you want with the docytype object
});

Reading stdin :

getDoctype.parseStdin(function (doctype) {
  // Do what you want with the docytype object
});

if you want to parse a string containing the XML

var xmlString =
    '<?xml version="1.0"?>'
  + '<!DOCTYPE greeting SYSTEM "hello.dtd">'
  + '<greeting>Hello, world!</greeting>';
getDoctype.parseString(xmlString, function(doctype) {
  // Do what you want with the docytype object
});

Keywords

FAQs

Package last updated on 22 Nov 2016

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