Trouble with Attributes when in Managed Code

A

Aldrin Leal

Hello,

I'm having some trouble when using InfoPath with managed Code. It's
meant to add a revision history entry to a Purchase Order document.

My code is written this way:

[InfoPathEventHandler(MatchPath="btnSubmit",
EventType=InfoPathEventType.OnClick)]
public void btnSubmit_OnClick(DocActionEvent e) {
String thisDocNSURI =
@"http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-04-09T02-30-31";

if (this.document.IsDirty) {
if (XdConfirmChoice.xdYes == this.document.UI.Confirm("Deseja
publicar sua revisão?", XdConfirmButtons.xdYesNo)) {
IXMLDOMNode rootHistóricos =
this.document.DOM.selectSingleNode("/my:pedido/my:HistóricoRevisões");

if (null == rootHistóricos) {
IXMLDOMNode parentNode =
this.document.DOM.selectSingleNode("/my:pedido");
IXMLDOMNode newElement =
this.document.DOM.createNode(DOMNodeType.NODE_ELEMENT,
"my:HistóricoRevisões", thisDocNSURI);

rootHistóricos = parentNode.appendChild(newElement);
}

IXMLDOMNode newHistórico =
this.document.DOM.createNode(DOMNodeType.NODE_ELEMENT,
"my:HistóricoRevisão", thisDocNSURI);
int numRevisão = 1;

if (null != rootHistóricos.childNodes)
numRevisão += rootHistóricos.childNodes.length;

IXMLDOMAttribute curAttribute = null;

curAttribute = (IXMLDOMAttribute)
this.document.DOM.createNode(DOMNodeType.NODE_ATTRIBUTE,
"my:NúmeroRevisão", thisDocNSURI);
curAttribute.value = numRevisão;
((IXMLDOMElement)
newHistórico).setAttributeNode(curAttribute);

curAttribute = (IXMLDOMAttribute)
this.document.DOM.createNode(DOMNodeType.NODE_ATTRIBUTE,
"my:DataRevisão", thisDocNSURI);
curAttribute.value = System.DateTime.UtcNow;
((IXMLDOMElement)
newHistórico).setAttributeNode(curAttribute);

curAttribute = (IXMLDOMAttribute)
this.document.DOM.createNode(DOMNodeType.NODE_ATTRIBUTE,
"my:ResponsávelRevisão", thisDocNSURI);
curAttribute.value = System.Environment.UserName;
((IXMLDOMElement)
newHistórico).setAttributeNode(curAttribute);

this.document.UI.Alert(rootHistóricos.xml);
this.document.UI.Alert(newHistórico.xml);

rootHistóricos.appendChild(newHistórico);
this.document.Save();
}
}

Whenever i reach the last appendChild call, i get this exception:

System.Runtime.InteropServices.COMException
The attribute
'{http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-04-09T02-30-31}ResponsávelRevisão'
on the element
'{http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-04-09T02-30-31}HistóricoRevisão'
is not defined in the DTD/Schema.

Tips are welcome :)

-- Aldrin Leal
 

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