Changing attribute value for an existing element - InfoPath Dev
in

InfoPath Dev

Changing attribute value for an existing element

Last post 01-20-2009 09:06 AM by ACrush. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 01-20-2009 08:51 AM

    Changing attribute value for an existing element

    I found some unexpected behaviour while developing my InfoPath 2003 compatible form template with C#.
    The problem is, I cannot change an attribute value on an existing element with the following code:

    Initial element
    <my:Employee xmlns:my="..." my:ID="" my:FirstName="Jane" my:LastName="Doe">Jane Doe</my:Employee>

    node = thisXDocument.selectSingleNode("my:Employee"); // OK
    attr = node.attributes.getNamedItem("my:ID"); // OK
    node.attributes.setNamedItem(attr).nodeValue = "14"; // COM Exception

    The debugger shows COM exceptions like E_FAIL or 0x80043001 which are not informative.
    The same code works with temporary elements:

    node = thisXDocument.DOM.createNode("my:Employee"); // OK
    node.attributes.setNamedItem(thisXDocument.DOM.createAttribute("my:ID")).nodeValue="14"; // OK

    Result:
    <my:Employee my:ID="" ></my:Employee> Assistance / advice appreciated.
  • 01-20-2009 09:06 AM In reply to

    Seems like I overcomplicated that one

    Apparently just attr.nodeValue = "14" should work.
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.