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}Resp
onsá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
Greg Collins [InfoPath MVP] - 29 Mar 2005 23:28 GMT
You've probably done this, but the first thing that needs to be done is to verify in the schema that the attribute actually exists, and that the spelling is the same.

Signature
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com
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}Resp
onsá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