I'm trying to get the value of an attribute in a Xml Node using razor. The node in question is from blog4umbraco and it's all the comments from a post.
My code looks like this:
var postComments = (@BlogLibrary.GetCommentsForPost(@Model.Id)); var allComments = @Library.ToDynamicXml(postComments); foreach (var comment in @allComments)
{ @Html.Raw(comment.name); @Html.Raw(comment.email); @Html.Raw(comment.website); @Html.Raw(comment.message);
}
The XML content of 'comment' is:
<comment id="1" nodeid="1139" created="22-01-2012 19:44:25">
<name>Joao</name>
<email>[email protected]</email>
<website>http://www.com.com</website>;
<message>Bla bla bla bla bla</message>
</comment>
I can get the value from all inner nodes, but how do I get the value from the attributes of the 'comment' node such as 'created'?
How to get attribute from current Xml Node
Hi there,
I'm trying to get the value of an attribute in a Xml Node using razor. The node in question is from blog4umbraco and it's all the comments from a post.
My code looks like this:
var postComments = (@BlogLibrary.GetCommentsForPost(@Model.Id));
var allComments = @Library.ToDynamicXml(postComments);
foreach (var comment in @allComments)
{
@Html.Raw(comment.name);
@Html.Raw(comment.email);
@Html.Raw(comment.website);
@Html.Raw(comment.message);
}
The XML content of 'comment' is:
<comment id="1" nodeid="1139" created="22-01-2012 19:44:25">
<name>Joao</name>
<email>[email protected]</email>
<website>http://www.com.com</website>;
<message>Bla bla bla bla bla</message>
</comment>
I can get the value from all inner nodes, but how do I get the value from the attributes of the 'comment' node such as 'created'?
Thanks in advance!
Have you tried this?
Think since 4.7.1 that should work.
Jeroen
Yes...
That's the . notation referred in the Razor blog posts part 6.
But that doesn't work... It says it doesn't exist...
'umbraco.MacroEngines.DynamicXml' does not contain a definition for 'created'
Edit: I'm using 4.7.1
Edit2: Oh man... Thanks... I'm pretty sure I already tried that... After all I read that part... But for some reason it works now... 8-|
is working on a reply...