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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ktxml

v1.0.6

Published

The xml reader for keytop!

Downloads

1

Readme

XML解析器

安装方法

npm install ktxml

该库依赖于: xmlreader, 请先安装依赖

npm install xmlreader

使用方法

以下方法均以该例子进行举例:

 <response id="1" shop="aldi">
  This is some other content
  <who name="james">James May</who>
  <who name="sam">
    Sam Decrock
    <location>Belgium</location>
  </who>
  <who name="jack">Jack Johnsen</who>
  <games age="6">
    <game>Some great game</game>
    <game>Some other great game</game>
  </games>
  <note>These are some notes</note>
</response>

1. 获取xml节点的字段

请注意, 数组类型和普通类型请区别对待. 数组使用getArrayText()

* 获取XML节点字段
* @param {string} xmlString xml字符串
* @param {string} param 字段参数
* @param {any} success 成功
* @param {any} failed 失败
getText(string, string, success, failed)

例子:

// 获取response 节点中的内容
ktxml.getText(xml_string, "response", (res)=>{
  console.log("SUCCESS=>" + res)
},
(err)=>{
  console.log("FAILED=>" + err)
})

得到回复:

SUCCESS=>This is some other content

2. 获取xml数组节点中的字段

请注意, 数组类型和普通类型请区别对待. 普通类型请用getText()

* 获取XML节点数组中的字段
* @param {string} xmlString xml字符串
* @param {string} param 字段参数
* @param {int} index 数组index
* @param {any} success 成功
* @param {any} failed 失败
getArrayText(xmlString, param, index, success, failed)

例子:

// 获取games中的game数组的第0项的内容

ktxml.getArrayText(xml_string, "response.games.game", 0, (res)=>{
  console.log("SUCCESS=>" + res)
}, (err)=>{
  console.log("FAILED=>" + err)
} )

得到回复

SUCCESS=>Some great game

3. 获取XML节点中的属性内容(成功回调格式为json)

请注意, 数组类型和普通类型请区别对待. 数组使用getArrayAttr()

* 获取XML中节点的属性
* @param {string} xmlString xml字段
* @param {string} param 参数
* @param {any} success 成功
* @param {any} failed 失败
getAttr(xmlString, param,success, failed)

例子:

//获取xml字段中 response的属性

ktxml.getAttr(xml_string, "response", (res)=>{
  console.log("SUCCESS=>" , res)
},
(err)=>{
  console.log("FAILED=>" + err)
})

得到回复(JSON)

SUCCESS=> { id: '1', shop: 'aldi' }

4. 获取XML数组节点中的属性内容(成功回调格式为json)

请注意, 数组类型和普通类型请区别对待. 普通类型使用: getAttr()

* 获取XML数组节点的属性
* @param {string} xmlString xml字段
* @param {string} param 参数
* @param {int} index 数组index
* @param {any} success 成功
* @param {any} failed 失败
getArrayAttr(xmlString, param, index, success, failed)

例子:

// 获取xml字段中 response中 who 数组 第1位的数据
ktxml.getArrayAttr(xml_string, "response.who", 1, (res)=>{
  console.log("SUCCESS=>" , res)
},
(err)=>{
  console.log("FAILED=>" + err)
})

得到回复(JSON)

SUCCESS=> { name: 'sam' }

5. 获取xml中的array方法

请注意, 获取了以后请自行查看需要使用的数据类型方法, 例如 获取字段 请用 .text() 获取属性名称请用 .attributes()

* 获取XML数组节点的属性
* @param {string} xmlString xml字段
* @param {string} param 参数
* @param {any} success 成功
* @param {any} failed 失败
getArray(xmlString, param, success, failed)

例子:

// 获取xml字段中 response中 who 数组 第1位的数据
ktxml.getArray(xml_string, "response.who", (res)=>{
  console.log("SUCCESS=>" , res)
  console.og(res[0].text())
},
(err)=>{
  console.log("FAILED=>" + err)
})

得到回复(JSON)

...
James May
库中使用到了 eval. 十分危险, 谨防注入