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 / March 2005

Tip: Looking for answers? Try searching our database.

Trouble with Attributes when in Managed Code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Aldrin Leal - 27 Mar 2005 19:19 GMT
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
 
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.