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

Little informative examples. #81

Open
heretic13 opened this issue Feb 21, 2018 · 4 comments
Open

Little informative examples. #81

heretic13 opened this issue Feb 21, 2018 · 4 comments

Comments

@heretic13
Copy link

Hello.

The idea of using namespaces is certainly original, but it is not always convenient. In general, I load the page from somewhere and I do not want to set namespaces.
It would be convenient to turn them off optionally.

Further.
I'm trying to parse the next line:

const htmlString=<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Galleries</title></head><body></body></html>;
I can not select /html/head/title for this line using namespace.

In your examples, a search is made for part of the path (for example, "/namespace:DeepChild").
I want/need to use the full path - /html/body/child1/child2/....

If I use namespaces, it does not work.

@JLRishe
Copy link
Collaborator

JLRishe commented Feb 22, 2018

If you use namespaces correctly, you should be able to use a full path just fine:

/ns:html/ns:body/ns:child/ns:child2

However, this library has an HTML mode which ignores namespaces on unprefixed node tests and is case insensitive on node names. I would advise using that in your case:

var expr = xpath.parse('/html/body/child1/child1');
var result = expr.select({ node: dom, isHtml: true });

@heretic13
Copy link
Author

"isHtml" flag is working. But I do not see it in the documentation.

Alternatively, I tried to do this without a flag, and nothing works for me. But maybe it's planned :)

https://pastebin.com/Fz1ETiPb

@JLRishe
Copy link
Collaborator

JLRishe commented Feb 22, 2018

I will add it to the documentation. Thank you for pointing that out.

The example in your pastebin doesn't work because the path is wrong. head and title are both in the http://www.w3.org/1999/xhtml namespace so the path needs to be /ns:html/ns:head/ns:title.

@heretic13
Copy link
Author

heretic13 commented Feb 22, 2018

Excellent. Thanks (this works).

I do not know if it's worth describing the situation with my example and the '/ns:html/ns:head/ns: title' solution in the documentation. This I leave to your discretion.

topic may be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants