Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to evaluate XPath for Element Attribute #3293

Open
luechtdev opened this issue Nov 22, 2021 · 1 comment
Open

Unable to evaluate XPath for Element Attribute #3293

luechtdev opened this issue Nov 22, 2021 · 1 comment
Labels
xpath XPath

Comments

@luechtdev
Copy link

Basic info:

  • Node.js version: v16.2.0
  • jsdom version: ^18.1.0

Minimal reproduction case

import { JSDOM } from "jsdom";

const xml = `
<PARAGRAPH>
    This is a text, about something, that happened on 
    <DATE ISO="20131117">17.November 2013</DATE>
    . It is a very important date.
</PARAGRAPH>
`;

const dom = new JSDOM(xml, {contentType: "application/xml"});
const doc = dom.window.document;

// 2: XPathResult.STRING_TYPE
const date = doc.evaluate("PARAGRAPH/DATE/@ISO", doc, null, 2, null).stringValue;

console.log(date);

I can't seem to be able to get XML Attributes using JSDOM and XPath Syntax on this XML Snippet.

<PARAGRAPH>
    This is a text, about something, that happened on 
    <DATE ISO="20131117">17.November 2013</DATE>
    . It is a very important date.
</PARAGRAPH>

By my understanding PARAGRAPH/DATE/@ISO is valid XPath Syntax for the Attribute and it's working just fine on sites like Xpather

Expected Result: / Result of Browser DOMParser: "20131117"

Actual Result w/ JSDOM: ""

Other non-working approaches

PARAGRAPH//DATE/@ISO,
string(PARAGRAPH/DATE/@ISO), XPath.FIRST_ORDERED_NODE_TYPE

The evaluation seems to come back empty.

@TimothyGu
Copy link
Member

Unfortunately, our XPath support has quite a few issues. If you must use XPath, I recommend that you use an alternative JavaScript implementation.

@TimothyGu TimothyGu added the xpath XPath label Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
xpath XPath
Projects
None yet
Development

No branches or pull requests

2 participants