Append Node Infopath -- PLEASE HELP

E

esebastian

Hello Everyone,
I have created a form in infopath that i am hosting in a visual studio
2005 project. The XML that is generated from the form gets saved into
a database .. this all works fine. Recently I've added some
functionality onto my project in Visual Studio 2005 c# code and i want
to append an XML node that i create to the XML that is generated from
my form when a certain button clicks. When i try and do this i get an
error ..see below for the code and the error message. I have no idea
what this means or how to fix it. I tried modifying the schema but
that didn't work, also there could be any number of nodes to append.
An example of the nodes to append are:

<Images> -- the parent node, this will always be appended onto the xml
from the form
<Ink>VALUE HERE</Ink>
<Photo>VALUE HERE</Photo> -- there could be zero to many
different ink and photo nodes applied on the fly
</Images>

Error Message:
Schema validation found non-data type errors

Here is the code i use to append the new xmlnode to the xml the form
generates.

XPathNavigator xn =
formControl1.XmlForm.MainDataSource.CreateNavigator();
XPathNavigator navigator =
xn.SelectSingleNode(Constants.MYFIELDS_FIELD, xmlnsm);

XmlElement elementToAppend = prepareXmlNodeForAppend("<Images/>");

navigator.AppendChild(elementToAppend.OuterXml);

------------------------------------

public XmlElement prepareXmlNodeForAppend(string xmlData)
{
XmlDocument xDoc = new XmlDocument();

byte[] bytes = Encoding.UTF8.GetBytes(xmlData);

using (MemoryStream memStream = new MemoryStream())
{
// Load the byte array into the memory stream
memStream.Write(bytes, 0, bytes.Length);

// Load the memory stream into the FormControl
memStream.Seek(0, SeekOrigin.Begin);
xDoc.Load(memStream);

// Close the memory stream
memStream.Close();
}
return xDoc.DocumentElement;
}
 

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