'2019/12/17'에 해당되는 글 1건

  1. 2019.12.17 node.js xpath 그리고 boolean
Programming/node.js2019. 12. 17. 13:26

이제야 눈에 띄는 DOM3 XPath 1.0 implementation..

그래서 문법을 많이 적용 못 받은건가? 최신은 3.1인 것 같은데 1.0이라서 기능들이 많이 빠진듯

 

DOM 3 XPath 1.0 implemention and helper for JavaScript, with node.js support.

[링크 : https://www.npmjs.com/package/xpath]

 

아무튼 boolean() 함수는 결과값이 boolean 타입이다(당연하지만)

[링크 : https://developer.mozilla.org/ko/docs/Web/XPath/Functions/boolean]

 

아래는 xpath node.js npm의 예제를 이용하여

/book 노드가 실제로 존재하는지 boolean()으로 체크하도록 수정한 내용이다.

> var xpath = require('xpath')
undefined
>
> var dom = require('xmldom').DOMParser
undefined
> var xml = ""
undefined
> var doc = new dom().parseFromString(xml)
undefined
console.log(xml)

undefined
> var nodes = xpath.select("//title", doc)
undefined
console.log(nodes[0].localName + ": " + nodes[0].firstChild.data)
title: Harry Potter
undefined
var test = xpath.select("boolean(/book)", doc)
undefined
console.log(typeof test)
boolean
undefined
console.log(test)
true

typeof로 체크시 boolean 타입으로 나오니.. 기존에 프로그램을 좀 수정해야 할 듯..

'Programming > node.js' 카테고리의 다른 글

node.js cookie 관련 함수들  (0) 2020.01.19
node.js crypto 모듈  (0) 2020.01.19
node.js JWT with refresh token  (0) 2019.12.10
node.js synchornous file write  (0) 2019.11.06
postgres on node.js  (0) 2019.09.24
Posted by 구차니