Adding a field node to exported xml subform

hi, I was wondering if anyone has had experience appending a field to an xml exported form or subform? the separately exported field is defined like so:

  <font size='8pt' color='fuchsia'/>

  !-- Document PDA		
  <font

size=‘8pt’ color=‘fuchsia’/>

     <field type='text' kind='editable' name='FLD_PDA_Update'>

        <code event='defaultvalue'>

           <formula

“1”

           </formula>

        </code>

        <code event='inputtranslation'>

           <formula>@If (@IsDocBeingSaved; @DeleteField; FLD_PDA_Update)

           </formula>

        </code>

  </field>

<run

  <font color='fuchsia'/> 
  <font size='8pt' color='fuchsia'/>!-- Determine if doc 

<run

  <font size='8pt' color='fuchsia'/>ws updated thru the PDA or WAP device

<run

  <font size='8pt' color='fuchsia'/>

i need to somehow get that field into the xml of an exported subform, and then reimport the whole thing back into a database.

any suggestions? is my question clear?

i looked a couple of the samples in designer help, and i can see i need to use the domParser.Document.DocumentElement.appendchild() method. i am just not sure how to get in the right place, underneather another node. in my situation, under a node.

please advise.

thanks,

theresa

Subject: can clone(deep clone) work? xml expert advice needed

in reference to my initial post I was thinking, can i open the xml pasted above into another stream and then clone it as a node (clonedFieldNode), with all it’s children… then subformDocElement.appendChild(clonedFieldNode)?

possible? what’s the best way?

thanks,

an xml beginner

Subject: RE: can clone(deep clone) work? xml expert advice needed

i tried it… but I get error “4576 Dom Operation Failed.”

maybe you can’t declare 2 domparsers in the same session… here’s my code:

Dim domParser As NotesDOMParser

Dim docNode As NotesDOMDocumentNode

Dim docRootNode As NotesDOMNode

Dim fieldDomParser As NotesDOMParser

Dim fieldDocNode As NotesDOMDocumentNode

Dim fieldDocRootNode As NotesDOMNode

Dim fieldElementNode As NotesDOMElementNode

Set domParser=session.CreateDOMParser(inputSubformXMLStream, outputSubformPlusFieldXMLStream)

domParser.Process

Set docNode = domParser.Document

Set docRootNode = docNode.DocumentElement

Set fieldDomParser=session.CreateDOMParser(fieldXMLStream, dummyStream)

fieldDomParser.Process

Set fieldDocNode = fieldDomParser.Document

Set fieldDocRootNode = fieldDocNode.DocumentElement

Set fieldElementNode = fieldDocRootNode.Clone(True)

If docRootNode.NodeName = “section” Then

Call docRootNode.AppendChild( fieldElementNode)

End If

Call domParser.Serialize()

any advice would be greatly appreciated.

thanks,

theresa

Subject: RE: can clone(deep clone) work? xml expert advice needed

I’ve not done much with xml in R6 so don’t know the answer but…You can declare 2 parsers. What you’ve done works right up to the appendchild. At that point you can append a new node but it refuses to accept a cloned node.

Perhaps you could try just appending a new node along the lines of

<xsl:include src=“c:\field.xml”/>

and pipe the output through xslt?

Subject: RE: can clone(deep clone) work? xml expert advice needed

i am having a hard time setting the prefix… i am sure i have the syntax right, but i keep getting a Dom Operation Error: namespace error.i have set the domparser doNamespaces property to true… is there something else I am missing?

I am trying to add a node just as you say

<xsl:include src=“c:\field.xml”/>

please advise. thanks, T

Subject: RE: can clone(deep clone) work? xml expert advice needed

Yes, I wasn’t thinking too clearly, of course you would have to turn the xml doc into an xsl stylesheet for that to work. However I’ve established that the problem is that you can’t transfer nodes from one tree to another. Don’t ask me why, maybe they all have to have the same sap group. The solution is to make your own clone, creating new nodes in the destination tree and copying the contents from the source nodes. I wrote the following function last night that does just that. Its fairly primitive, ignoring things you probably won’t need but it copies elements and their attributes and the result can be appended. If you need anything else you should be able to extend it. I’ve only tested it using the simple files shown at the end.

Just replace the line in your code containing ‘clone’ with

Set fieldElementNode =copyTree(docNode,Nothing, fieldDocRootNode)

The key is that it uses docNode from the first tree to create new nodes.

Function copyTree( d As NotesDOMDocumentNode, parent As NotesDOMNode, n As NotesDOMNode) As NotesDOMNode

Dim ss As New notessession

Dim nn As NotesDOMNode

Dim cn As NotesDOMNode



If n Is Nothing Then Exit Function

If n.IsNull Then Exit Function



Select Case n.NodeType

Case DOMNODETYPE_UNKNOWN_NODE 

	Exit Function		

Case DOMNODETYPE_ELEMENT_NODE 

	Dim en As NotesDOMElementNode

	Dim map As NotesDOMNamedNodeMap

	Dim an As NotesDOMNode

	Dim i&

	

	Set en=d.CreateElementNode(n.NodeName)

	Set map=n.Attributes

	For i=1 To map.NumberOfEntries

		Set an= map.GetItem( i& )

		Call en.SetAttribute(an.nodeName,an.nodeValue)

	Next

	Set nn=en

Case DOMNODETYPE_ATTRIBUTE_NODE :

	Exit Function

Case DOMNODETYPE_TEXT_NODE  :

	Set nn=d.CreateTextNode(n.NodeName)

Case DOMNODETYPE_CDATASECTION_NODE  :

	Set nn=d.CreateCdataSectionNode(n.NodeName)

Case DOMNODETYPE_ENTITYREFERENCE_NODE  :

	Set nn=d.CreateEntityReferenceNode(n.NodeName)

Case DOMNODETYPE_ENTITY_NODE  :

	Exit Function

Case DOMNODETYPE_PROCESSINGINSTRUCTION_NODE  :

	Dim pn As NotesDOMProcessingInstructionNode

	Set pn=n

	Set nn=d.CreateProcessingInstructionNode(pn.target,pn.data)		

Case DOMNODETYPE_COMMENT_NODE  :

	Set nn=d.CreateCommentNode(n.NodeName)

Case DOMNODETYPE_DOCUMENT_NODE  :

	Set nn=d.CreateDocumentNode()

Case DOMNODETYPE_DOCUMENTTYPE_NODE  :

	Exit Function

Case DOMNODETYPE_DOCUMENTFRAGMENT_NODE  :

	Exit Function 'can't actually occur in a dom

Case DOMNODETYPE_NOTATION_NODE  :

	Set nn=d.CreateNotationNode(n.NodeName)

Case DOMNODETYPE_XMLDECL_NODE  :

	Exit Function

End Select

nn.NodeValue=n.NodeValue

If n.HasChildNodes Then

	Set cn=n.FirstChild

	While Not cn.IsNull

		Call copyTree (d, nn, cn)

		Set cn=cn.NextSibling

	Wend

End If

If Not parent Is Nothing Then	

	Call parent.AppendChild ( nn )

End If

Set copyTree=nn

End Function

-----file 1

<?xml version='1.0' encoding='UTF-8'?>

----- + file 2

<?xml version='1.0' encoding='UTF-8'?>

fff

-----produces file 3

<?xml version="1.0" encoding="UTF-8"?>

fff