Appending new nodes with attributes *without* using cloneNode()

G

Greg S

I have repeating nodes that contains attribute fields. Whenever I have to
add a new node in code, I've been using "cloneNode(true)" to copy an
existing node, or the blank default one created by InfoPath, as a quick way
to append new items. This has worked great until a situation occured where
the intial blank row doesn't exist. An example is when a user submit's via
email. When the recipient gets the email, the blank row is removed and I
have no way to add a new node that contains attributes. I can add the new
node without attributes, but any attempt to create an attribute results in
the InfoPath error:

The attribute 'x' on the element '{http://schemas...blah...blah..}mynode' is
not defined in the DTD/Schema.

But it *is* defined.
I've tried
mynode.setAttribute "x", "newvalue"
and
mynode.setAttribute "my:x", "newvalue"
and
set att = XDocument.DOM.createAttribute("my:x")
mynode.attributes.setNamedItem att
and
set att = XDocument.DOM.createAttribute("x")
mynode.attributes.setNamedItem att

I can set the attribute on the node before I append the node to the
document, but the minute I append the node to the doc it fails.

I've verified that the xml produced with the cloneNode method is identical
to what I'm trying to append. Any ideas? I've got to missing something
simple here.

thanks,
Greg
 
F

Franck Dauché

Hi Greg,

Are you using a schema that was designed in IP or one that was designed
outside such as with XMLSpy? If you used IP to build your schema, attributes
will be manipulated as nodes, not attributes.

Regards,

Franck Dauché
 
G

Greg S

Its a schema I created and built directly in InfoPath -- and I set the
fields to be attributes as in "type = Field (attribute)". Yes, the default
is "type = Field (element)", but I needed to use attributes.
 
F

Franck Dauché

Hi Greg,

Can you try with a XMLSpy-based schema? I had similar issues with
attributes about 1 year ago. setAttributeNode as well as DOM.createAttribute
work great ... on an XMLSpy-based schema, but not on an IP-based schema.

Regards,

Franck Dauché
 

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