Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I am getting error while trying to get nodes by XPath. Any help is appreciated.
var xpathQuery = string.Format("//{0}/[@nodeName='{1}']/{2}//[@nodeTypeAlias='{3}' or @nodeTypeAlias='{4}']", DocumentTypes.Kempinski, language.ToLower(), DocumentTypes.CorporatePressReleasesLandingPage, DocumentTypes.TemplateAContentWithTextOnly, DocumentTypes.TemplateBContentWithFeaturedImage);
I use glass mapper for DocumentTypes. Here is my umbraco backend structure:
<Kempinski> <en name="en"> <CorporatePressReleasesLandingPage> <TemplateAContentWithTextOnly> </TemplateAContentWithTextOnly> <TemplateBContentWithFeaturedImage> </TemplateBContentWithFeaturedImage> </CorporatePressReleasesLandingPage> </en> </Kempinski>
I want to take all Nodes with Document Types have alias "TemplateAContentWithTextOnly" and "TemplateBContentWithFeaturedImage"
And i get this error. Anyone have any idea?
Regard,
Phong.
Hi Phong,
Don't immediatly see what is wrong with the query, but I'm no xpath expert.
What I would do is simplify the query and bits.
So I would start getting the Kempinskie part first. Than the language node...and so on.
That way you can find the part of the query that breaks.
Dave
Hi Dave,
Thank for your advice.
I did exactly what you said to me but every single time i tried to get a node, it was always null, even the first one: Kempinski.
And i get more confused about this. Do you have any idea Dave?
The xml you posted is from the umbraco.config file in the App_Data folder ?
I tested this query and this works on the supplied xml fragment :
//Kempinski/*[@nodeName='en']/CorporatePressReleasesLandingPage/*[self::TemplateAContentWithTextOnly or self::TemplateBContentWithFeaturedImage]
There's a couple of tiny bugs in the XPath - try this instead:
string.Format("//{0}[@nodeName='{1}']/{2}//*[@nodeTypeAlias='{3}' or @nodeTypeAlias='{4}']"
Notice that there needs to be a "path step" (e.g. *, elementname or similar) before a predicate (thing in square brackets).
Another version could be this:
string.Format("//{0}[@nodeName='{1}']/{2}//*[self::{3} or self::{4}]"
(I like that better, but it may not be as obvious if you're not familiar with XPath)
Hope that helps,
/Chriztian
Thank you so much Dave and Chriztian for your help, i found a solution.
I change my string format to:
string.Format("//{0}/*[@nodeName='{1}']/{2}/*[local-name()='{3}' or local-name()='{4}']"
I also tried your ideas but it didn't work, so sorry for my late reply.
It took me a lot of time but i think i get better with XPath now.
Thank you guys again for your kindness. Love this comunity.
Regard, Phong.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Expression must evaluate to a node-set while using XPath
I am getting error while trying to get nodes by XPath. Any help is appreciated.
I use glass mapper for DocumentTypes. Here is my umbraco backend structure:
I want to take all Nodes with Document Types have alias "TemplateAContentWithTextOnly" and "TemplateBContentWithFeaturedImage"
And i get this error. Anyone have any idea?
Regard,
Phong.
Hi Phong,
Don't immediatly see what is wrong with the query, but I'm no xpath expert.
What I would do is simplify the query and bits.
So I would start getting the Kempinskie part first. Than the language node...and so on.
That way you can find the part of the query that breaks.
Dave
Hi Dave,
Thank for your advice.
I did exactly what you said to me but every single time i tried to get a node, it was always null, even the first one: Kempinski.
And i get more confused about this. Do you have any idea Dave?
Phong.
Hi Phong,
The xml you posted is from the umbraco.config file in the App_Data folder ?
I tested this query and this works on the supplied xml fragment :
Dave
Hi Phong,
There's a couple of tiny bugs in the XPath - try this instead:
Notice that there needs to be a "path step" (e.g. *, elementname or similar) before a predicate (thing in square brackets).
Another version could be this:
(I like that better, but it may not be as obvious if you're not familiar with XPath)
Hope that helps,
/Chriztian
Thank you so much Dave and Chriztian for your help, i found a solution.
I change my string format to:
I also tried your ideas but it didn't work, so sorry for my late reply.
It took me a lot of time but i think i get better with XPath now.
Thank you guys again for your kindness. Love this comunity.
Regard, Phong.
is working on a reply...