-
Notifications
You must be signed in to change notification settings - Fork 55
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
Additional functionality for searching by path? #68
Comments
I love this! It feels very "glob" like and natural, and doesn't change any existing semantics. Would definitely merge this! |
The only issue I can see with my original approach and how descendant paths are implemented at present is that the “.” (period) is allowed in XML tag names. Would it make more sense for me to follow the XPath convention of using "/' and "//"? Sadly, this would be a breaking change from your current implementation, and a better solution might be to add a method to XmlDocument called "query" and implement this portion of XPath with the hopes of adding other XPath query features after. I think the latter approach is probably the better one. |
Hm, well I wouldn't want to optimize for cases that should be pretty rare (been a while since XAML 😂 ) - perhaps we could allow escaping periods somehow in the search string? But this is already a problem with the current implementation so I don't think supporting ".." would be a breaking change. I'm not sure supporting a small amount of Actual XPath would be better than not supporting it at all. Like, if you knew XPath syntax already you'd likely run into a wall pretty quick, so your existing knowledge won't be all that useful. Better I think to just have a tiny language of our own. |
Sounds good. I will stick with . (child) and .. (descendant) as query contexts.
Since the backslash isn’t an acceptable in an element name, I could add backslash support to the existing descendantWithPath method. For example:
```
// historic paths that would already be in use with this lib
bookNode.descendantWithPath(‘author.name’);
// escaped paths in cases where a node name includes one or more periods
// for example:
//
// <styles>
// <component.checkbox color="white" borderColor="black" />
// </styles>
stylesNode.descendantWithPath('component\.checkbox');
|
I like the backslash character idea but note that it would require two of them, like |
Would you be willing to consider a pull request that enhances the functionality of xmldoc to allows for finding all descendants by a path? What I am thinking is that it will function like descendantWithPath, but with some additional substrings that are useful:
What I am thinking is that it will function like descendantWithPath, but with some additional substrings that are useful:
. = direct child
.. = anywhere in tree
This could be useful for extracting things like all items from a navigation tree, such as:
var itemNodes = itemsNode.descendantsWithPath("..item")
would return an array of all<item>
nodes.This would allow other types of nested paths as well:
var bookPublisherNodes = inventoryNode.descendantsWithPath("books.book..publisher")
would return an array of all<publisher>
nodes.The text was updated successfully, but these errors were encountered: