appendChild using C#

R

RickM

I know this has been brought up before but none of the posts have any
solutions. So I will ask again.

Trying to add a new row to a repeating table programmatically.

The XML looks something like this

..
..
..
<Title>blah</Title>
<Term>Blah</Term>
<Funding>
<BeginDate>2004-06-06</BeginDate>
<EndDate>2004-06-06</EndDate>
<Amount>999</Amount>
<Year>2005</Year>
</Funding>
..
..
..
I want to add another Funding Row

Code looks like this:
IXMLDOMNode Funding=thisXML.selectSingleNode("//s0:Funding");
//Create a new "Funding Element"
IXMLDOMNode newFunding=thisXML.createNode(1,"Funding","http://www.blah.com");
//Create the Funding Elements
IXMLDOMNode End=thisXML.createNode(1,"BeginDate","http://www.blah.com");
IXMLDOMNode Start=thisXML.createNode(1,"EndDate","http://www.blah.com");
IXMLDOMNode Amt=thisXML.createNode(1,"Amount","http://www.blah.com");
IXMLDOMNode Year=thisXML.createNode(1,"Year","http://www.blah.com");
//Add the children to the new Funding element
newFunding.appendChild(End);
newFunding.appendChild(Start);
newFunding.appendChild(Amt);
newFunding.appendChild(Year);
//Add the new Funding Node
Funding.appendChild(newFunding);

This is where I get the infamous error
{http://www.blah.com}Funding' is unexpected according to content model
of parent element '{http://www.blah.com}Funding'

I have seen that quite a few other people have posted with this same
problem but I have never seen a solution.

Thanks
Rick M
 
A

Andrew Watt [MVP - InfoPath]

Rick,

A quick glance at your code suggests you are trying to add the new
Funding node as a child node to the existing Funding node when I
assume that what you want to do is add it as a sibling node.

I think that's why you are getting the error message you are
describing.

Andrew Watt
MVP - InfoPath
 
R

RickM

Andrew Watt said:
Rick,

A quick glance at your code suggests you are trying to add the new
Funding node as a child node to the existing Funding node when I
assume that what you want to do is add it as a sibling node.

I think that's why you are getting the error message you are
describing.

Andrew Watt
MVP - InfoPath

Thanks Andrew I will give that a try, I am kinda new to the XML thing
but am learning the best way; by making mistakes!

RickM
 

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