Child Nodes's Child Node creation

Child Nodes's Child Node creation

Post by jon » Sun, 17 Feb 2002 12:17:30



How do you create a node name "a" with a chile node "b".

the "b" node have 5 child nodes of its own "1 to 5".

I try to do this, but it seems the NodeType doesn't have the method
createNode....

What can I do and how do I do it.

 
 
 

Child Nodes's Child Node creation

Post by Devin Harri » Sun, 17 Feb 2002 14:47:44


I prefer the appendchild method for this.  The domdocument
creates the elements and then you piece them together.  
Alternately, you can load a doc and append new info to
it.  Here is some simple vbscript demonstrating what you
want ot accomplish (I hope):

'**********************************************
'  vbscript
'**********************************************
dim root, nodeA, nodeB, B1, B2

set xdoc = createobject("msxml2.domdocument")
xdoc.async = false

set root = xdoc.createElement("ROOT")

xdoc.appendchild(root)  '  establish the document root

' create the children the same way

set nodeA = xdoc.createElement("nodeA")

set nodeB = xdoc.createElement("nodeB")

set B1 = xdoc.createElement("B1")
set B2 = xdoc.createElement("B2")

B1.text = "This is the first element."
B2.text = "This is element two."

' append them properly

root.appendchild(nodeA)
nodeA.appendChild(NodeB)
NodeB.appendChild(B1)
NodeB.appendChild(B2)

msgbox xdoc.xml

Quote:>-----Original Message-----
>How do you create a node name "a" with a chile node "b".

>the "b" node have 5 child nodes of its own "1 to 5".

>I try to do this, but it seems the NodeType doesn't have
the method
>createNode....

>What can I do and how do I do it.

>.


 
 
 

Child Nodes's Child Node creation

Post by Bruce Taima » Fri, 22 Feb 2002 02:03:38


When you use the createNode off the domdocument, it will return a node that
you can then append on.

For example

dim dom as MSXML2.DomDocument30
set dom = new MSXML2.DomDocument30

dim myNodeA as MSXML2.IXMLDomNode
dim myNodeB as MSXML2.IXMLDomNode

set myNodeA = dom.CreateNode(NODE_ELEMENT, "A", "")
set myNodeB = dom.CreateNode(NODE_ELEMENT, "B", "")

myNodeA.AppendChilde(myNodeB)

Bruce Taimana

Microsoft Developer Support/XML WebData/Visual Basic WebData Group

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.

? 2001 Microsoft Corporation. All rights reserved.

 
 
 

1. use context node's value, but test child nodes' values

I have an xml structure like:

<Messages>

        <References>
            <Reference>A</Reference>
            <Reference>B</Reference>
            <Reference>C</Reference>
        </References>
    </Message>
    ...
</Messages>

I want to keep Message as the context node, but create a node test to
examine the values of all Reference nodes.  How do I formulate the xpath
test?

I've tried:

<xsl:value-of select="count(//Messages/Message[Reference = 'C'])"/>

but it doesn't work.

Can anyone correct my syntax?

Thanks,

Craig Buchanan

2. Networking Documentation - Call for Data

3. How to get Value-Of current node without Value-Of children's nodes?

4. More fire on the Sears Rumor

5. copy a node's text and children, but not the node itself

6. How to use a variable declare with <xsl:variable>?

7. XSLT - Using When test on Child node - One and Only One Child

8. How to get Mailto:'s to open in Agent instead of Netscape/mail

9. Problem getting node children and text without the node tag

10. Remove child node from root node asp

11. XSL: Testing whether node is unique by multiple child nodes?

12. child nodes include artificial text nodes !!!!