views:

364

answers:

1

I'm binding a control to an XmlDocument and using the "XPath" binding expression to output the data:

<div class="Bio"><%# XPath("Biography") %></div>

However, this returns the InnerText property of the "Biography" element, not the InnerXml. This means it strips all inner tags from it, which is not what I want.

I looked through the XPathBinder object, but I can't find anyway to get it to return InnerXml rather than InnerText

A: 

Binding.XPath returns a value rather than a node, so you won't be able to get the InnerXml this way. Can you define a method that returns SelectSingleNode(...).InnerXml instead? If you define a method such as

public string GetInnerXml(object o)
{
    string val = String.Empty;
    XmlNode parent = o as XmlNode;
    XmlNode child = parent.SelectSingleNode("bob/fred");
    if (child != null)
        val = child.InnerXml;
    return val;
}

then invoke this from your binding expression, this ought to do the trick. Code ought to be correct, but I haven't tested it so there may be errors.

Ade
Not what I was hoping for, but I'll make you the accepted answer since you at least told me I can't do what I want...
Deane