Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / April 2007

Tip: Looking for answers? Try searching our database.

add optional attribute to element if missing from document?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Deken - 29 Mar 2007 18:14 GMT
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
Thierry Coita - 02 Apr 2007 10:18 GMT
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

> In Infopath 2003, is it possible to add a missing optional attribute to an
> element?  
[quoted text clipped - 12 lines]
>
> Deken
Thierry Coita - 02 Apr 2007 10:36 GMT
In my original example loesch is a IXMLDOMNode so please replace it by:

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

for that my example work.
Deken - 02 Apr 2007 19:26 GMT
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

> Hi Deken,
>
[quoted text clipped - 31 lines]
> >
> > Deken
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.