[IronPython] XmlDocument or XDocument in Python/Silverlight

Jimmy Schementi Jimmy.Schementi at microsoft.com
Tue Jul 15 11:42:02 CEST 2008

Have fun =) Here's your answer:

There is no "first class support" for createTextNode (ie. a managed API that calls directly into the browser's native code). However, any javascript function can be called from managed code with "Invoke" so you could do this:

newtext = HtmlPage.Document.Invoke("createTextNode", "Some text added dynamically")
HtmlPage.Document.p1.Invoke("appendChild", newtext)

The "appendChild" call needs to be invoked as well, since the managed "AppendChild" equivalent only takes a HtmlElement, and Invoke will return a ScriptObject, and you can't cast a ScriptObject to a HtmlElement.


From: users-bounces at lists.ironpython.com [users-bounces at lists.ironpython.com] On Behalf Of Jonathan Slenders [jonathan at slenders.be]
Sent: Monday, July 14, 2008 10:36 PM
To: Discussion of IronPython
Subject: Re: [IronPython] XmlDocument or XDocument in Python/Silverlight

Thank you, Jimmy.

At the moment, I'm at a summercamp and stay there until the end of the month. Therefore, I've been inactive at this newsgroup.


2008/7/15 Jimmy Schementi <Jimmy.Schementi at microsoft.com<mailto:Jimmy.Schementi at microsoft.com>>:
Jonathan Slenders wrote:
> And another question, which is rather Silverlight then IronPython
> related. I hope it's okey to ask it here.
> How should I create a TextNode from Silverlight with IronPython code?
> In javascript, one would:
> node = document.createTextNode("text"); element.appendChild(node);
> According to the MSDN documentation, the HtmlDocument class doesn't
> have a createTextNode, and I can't find it anywhere else. Michael his
> book has been extremely useful for me, but he uses innerHtml which i
> really don't like. InnerHtml is is an old-style method for DOM-
> manipulation, and unsafe by definition. (it allows you to insert HTML
> code)

Did you figure this out yet? Actually, not sure of the answer, but I "think" Silverlight doesn't support this. But it should. I sent a mail off to the Silverlight guys who work on the HTML bridge a while ago. I'll check back with them again, and get back to you.

Users mailing list
Users at lists.ironpython.com<mailto:Users at lists.ironpython.com>

More information about the Ironpython-users mailing list