# Using DOMParser in a function node?

**URL:** <https://discourse.nodered.org/t/using-domparser-in-a-function-node/62954>\
**Category:** General\
**Tags:** function-node\
**Created:** [23 May 2022 08:41 UTC](https://discourse.nodered.org/t/using-domparser-in-a-function-node/62954 "2022-05-23T08:41:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dugite-code](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dugite-code/32/3438_2.png) [@dugite-code](https://discourse.nodered.org/u/dugite-code)\
**Post date:** [23 May 2022 08:41 UTC](https://discourse.nodered.org/t/using-domparser-in-a-function-node/62954/1 "2022-05-23T08:41:09Z")

</div>

I'm trying to use the [xpath](https://www.npmjs.com/package/xpath) module in a function node by adding it into the function node setup. So far so good, the main issue I'm running into is how to parse the html string output from a `HTTP request` for use with the xpath module.

My understanding is the function setup is equivalent to `xpath = require('xpath')` and so I can't get `dom = require('xmldom').DOMParser` this way?

Or is there a better way of using xpaths in Node-Red? I know there are css selectors however I am using body text as part of the xpath so it's not useful in this case.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [23 May 2022 09:36 UTC](https://discourse.nodered.org/t/using-domparser-in-a-function-node/62954/2 "2022-05-23T09:36:01Z")

</div>

According to that packages readme, you also need to install the xmldom package. Then you will be able to get access as `const dom = xmldom.DOMParser`.

---

<div class="post-metadata">

**Author:** ![dugite-code](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dugite-code/32/3438_2.png) [@dugite-code](https://discourse.nodered.org/u/dugite-code)\
**Post date:** [24 May 2022 01:13 UTC](https://discourse.nodered.org/t/using-domparser-in-a-function-node/62954/3 "2022-05-24T01:13:29Z")

</div>

🤦‍♂️ Ha, of course! Well that was obvious, couldn't see the forest through the trees yesterday for some reason. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 June 2022 01:13 UTC](https://discourse.nodered.org/t/using-domparser-in-a-function-node/62954/4 "2022-06-07T01:13:59Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
