I'm no XPath expert so this might be easy, but I'm trying to create an XPath which returns the current node and it's childeren. I don't want the children of those children. Here's what I've currently got (in C#):
var allDocs = xmlDocument.CreateNavigator();
if (allDocs != null)
{
//Get all media items that have the allowed media type.
var expr = !string.IsNullOrEmpty(allowedMediaTypes) ?
allDocs.Compile("//*[@nodeTypeAlias and contains('" + allowedMediaTypes + "',concat(',',@nodeType,','))]")
: allDocs.Compile("//*[@nodeTypeAlias]");
try
{
var iterator = allDocs.Select(expr);
while (iterator.MoveNext())
{
//do stuff
}
}
catch (Exception) { }
}
This returns the current node and all allowed descendants, but I only need the children. Any tips?
XPath get current node and children
Hello,
I'm no XPath expert so this might be easy, but I'm trying to create an XPath which returns the current node and it's childeren. I don't want the children of those children. Here's what I've currently got (in C#):
This returns the current node and all allowed descendants, but I only need the children. Any tips?
Jeroen
Maybe try changing "//" to "/" and using the child selector?
Wouldn't that just return the children and not the current node?
Jeroen
Hi Jeroen,
The problem is those greedy double-slashes. You could try something like this?
That would get the current node (if it has an "nodeTypeAlias" attribute), and all it's children that have that "nodeTypeAlias" attribute too.
Hope it helps?
Cheers, Lee.
Hi Lee,
Thanks that's what I was looking for. Working on another nice feature for DAMP 2.0 :-).
Jeroen
Cool, glad I could help. Looking forward to DAMP 2.0!
Cheers, Lee.
is working on a reply...