add optional attribute to element if missing from document?

D

Deken

In Infopath 2003, is it possible to add a missing optional attribute to an
element?

We have a dropdown list of values that can be assigned as the attribute
value. Alternatively, it's OK to have no value at all - and there's the
problem. Going from no value at all to one of the values from the dropdown
list reports "Attempt to modify a read-only node." It appears to do so prior
to firing any event I can script for, or we could select the node and add the
attribute we need to it.

I've seen the description of how to remove blank attributes, but not how to
add attributes that the schema allows but does not require.

TIA for any answers, and even more for a solution!

Deken
 
T

Thierry Coita

Hi Deken,

For information if your attribute is a non-string type you need to enter
value in this field for that Infopath accept to validate it.

For add an attribute with C# you can do the following:

//Select the element where you want to insert your attribut
IXMLDOMElement oElement =
(IXMLDOMElement)thisXDocument.DOM.selectSingleNode("/Root/yourElement");
IXMLDOMAttribute NewAttribute =
(IXMLDOMAttribute)loesch.ownerDocument.createNode((int)DOMNodeType.NODE_ATTRIBUTE, "AttributeName", "");
NewAttribute.text = "AtrributeValue";
oElement.setAttributeNode(NewAttribute);

Hope this Help

Thierry Coita
 
T

Thierry Coita

In my original example loesch is a IXMLDOMNode so please replace it by:

thisXDocument.DOM.selectSingleNode("/Root/yourElement")

for that my example work.
 
D

Deken

Thank you, Thierry. Unfortunately, this doesn't help. First, for a variety
of reasons, we're unable to use managed code, so C# is not available. I
could probably translate into JScript but don't see the point: When the
dropdown list is changed no event appears to fire before the node is reported
to be read-only and the action fails. Not even "OnBeforeChange" works - a
breakpoint set in that event handler (using the "debugger;" statement) is
never reached. OnLoad for the document might work, and I could add the
attribute for each location where it's allowed but that effectively makes the
attribute required, which is not what we want.

I suspect that there's something I'm missing but I am missing it.

I do appreciate your assistance, though!

Deken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top