Skip to content
This repository has been archived by the owner on Nov 12, 2017. It is now read-only.

difficulty filtering with a default namespace #10

Open
jennybc opened this issue May 19, 2016 · 3 comments
Open

difficulty filtering with a default namespace #10

jennybc opened this issue May 19, 2016 · 3 comments

Comments

@jennybc
Copy link

jennybc commented May 19, 2016

I can use an XPath query in the Console that xmlview tells me is invalid. In general, I can't use the xml_view XPath filter in the presence of a default namespace, i.e. when I need to do d1:foo.

library(xml2)
library(xmlview)
x <- read_xml('
  <root xmlns = "http://foo.com">
    <si>
      <t>country</t>
    </si>
    <si>
      <t>continent</t>
    </si>
  </root>
  ')
xml_find_all(x, "//d1:t", xml_ns(x))
#> {xml_nodeset (2)}
#> [1] <t>country</t>
#> [2] <t>continent</t>
#xml_view(x, add_filter = TRUE)

screen shot 2016-05-19 at 3 08 09 pm

@hrbrmstr
Copy link
Owner

(I was wondering when someone wld hit this :-)

thx for filing the bug and i'll tag it as such when not on mobile and see
how hard it will be to do the xml2 default namespace code gen (shldn't be
bad)

On Thu, May 19, 2016 at 6:41 PM, Jennifer (Jenny) Bryan <
notifications@github.com> wrote:

I can use an XPath query in the Console that xmlview tells me is invalid.
In general, I can't use the xmview XPath filter in the presence of a
default namespace, i.e. when I need to do d1:foo.

library(xml2)
library(xmlview)x <- read_xml(' country continent ')
xml_find_all(x, "//d1:t", xml_ns(x))#> {xml_nodeset (2)}#> [1] country#> [2] continent#xml_view(x, add_filter = TRUE)

[image: screen shot 2016-05-19 at 3 08 09 pm]
https://cloud.githubusercontent.com/assets/599454/15411252/8bc91b84-1dd3-11e6-8530-ce36a8a1c04a.png


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#10

@jennybc
Copy link
Author

jennybc commented May 19, 2016

The thing is ... it looks like it's already there! I tried to figure this out for myself before opening this.

Here's where it feels like you've already handled this:

self.rcode.innerText = "xml2::xml_find_all(" +
self.glob.xmlDocName + ", '" +
self.xpath.value + "', ns=xml2::xml_ns(" +
self.glob.xmlDocName + "))";
self.rcode.textContent = "xml2::xml_find_all(" +
self.glob.xmlDocName + ", '" +
self.xpath.value + "', ns=xml2::xml_ns(" +
self.glob.xmlDocName + "))";

@jennybc
Copy link
Author

jennybc commented May 19, 2016

Oh. I think that's just for the helpful R code you provide if user likes the XPath result, but it's not the business end of the filtering. It seems the actual filtering is happening on the js side and I don't know how to fix namespace resolution there 😔.

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

No branches or pull requests

2 participants