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

getAttributeNS(xml, 'lang') returns null #1276

Closed
msklvsk opened this issue Oct 27, 2015 · 6 comments
Closed

getAttributeNS(xml, 'lang') returns null #1276

msklvsk opened this issue Oct 27, 2015 · 6 comments

Comments

@msklvsk
Copy link

msklvsk commented Oct 27, 2015

<element xml:lang="uk"></element>
doc.documentElement.getAttributeNS('http://www.w3.org/XML/1998/namespace', 'lang');
// null
@domenic
Copy link
Member

domenic commented Oct 27, 2015

Can you provide a full example of jsdom code I could run by itself?

@msklvsk
Copy link
Author

msklvsk commented Oct 28, 2015

Sure,

var jsdom = require('jsdom').jsdom;

var doc = jsdom('<element xml:lang="uk"></element>', {
    parsingMode: 'xml'
});

var xmlns = 'http://www.w3.org/XML/1998/namespace';
var lang = doc.documentElement.getAttributeNS(xmlns, 'lang');

console.log(lang);  // null, while 'uk' for XMLDocument in a browser

@domenic
Copy link
Member

domenic commented Nov 7, 2015

Thanks! There's a hope that this will get fixed in #1247, but I will definitely work on it afterward, in any case. It might be a while though; I am on vacation + at conferences and meetings until November 23.

@domenic
Copy link
Member

domenic commented Nov 26, 2015

This was not fixed by #1247.

Unfortunately this is an issue with our XML parser, htmlparser2 :(. It only gives its attribs object in the form { qualifiedName1: value1, qualifiedName2: value2 }, instead of giving information about namespace and prefix.

That is, it gives { 'xml:lang': 'uk' }, instead of something more useful like [{ prefix: 'xml', localName: 'lang', namespace: 'http://www.w3.org/XML/1998/namespace', value: 'uk' }]. I am assuming the XML spec says that the xml prefix is automatically mapped to the http://www.w3.org/XML/1998/namespace namespace?

So to really fix this, we either need to get htmlparser2 to give more information, or we need to replace our XML parser. Hmm. /cc @fb55 @inikulin.

@fb55
Copy link
Contributor

fb55 commented Nov 26, 2015

This is out of scope for htmlparser2. https://github.com/isaacs/sax-js handles namespaces, perhaps that's a better alternative for XML parsing.

@Sebmaster
Copy link
Member

This will be fixed by #1303.

Sebmaster pushed a commit that referenced this issue Dec 2, 2015
Fixes #393. Fixes #651. Fixes #415 (wasn't quite applicable). Fixes #1276.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants