|
-
Jul 29th, 2003, 07:08 AM
#1
Thread Starter
Registered User
xml, help?!
hi,
how can i load a xml file, then be able to add, delete, rename nodes from a windows form? it would be nice if someone could send me some sample code, thanks
-
Jul 29th, 2003, 08:08 AM
#2
Addicted Member
Here we go:
dim xmlDoc As New XmlDocument()
'*load xml file
xmlDoc.Load("c:\some.xml")
'*find node
dim node1 as xmlelement
node1=rootNode.SelectSingleNode("child::somenode")
dim str as string
'*get text from node
str=node1.innertext
'* set some text to node and save xml file
node1.innertext="some text"
xmlDoc.save("c:\some.xml")
I hope that helps.
regard j
-
Jul 29th, 2003, 08:37 AM
#3
Thread Starter
Registered User
thanks,
and how do we add and remove a complete node?
-
Jul 29th, 2003, 10:42 AM
#4
Adding and removing work a lot like in a normal collection. You can select a node and then use Remove to remove it. To add then select the parent of the node you want to add then create and append the new node. Check out the XMLDocument object methods or documentation and you should be able to figure it out.
-
Jul 29th, 2003, 10:53 AM
#5
Thread Starter
Registered User
what if we have something like :
<parent>
<child id=1/>
<child id=3/>
<child id=4/>
</parent>
and wanted to add a child node , between 1 and 3 ( <child id=2/> ), is it possible?
( the order is important in my case )
thanks again
-
Jul 29th, 2003, 10:59 AM
#6
Thread Starter
Registered User
and can we find out how deep are xml file is ??? ( the depth of the deepest node )
-
Jul 29th, 2003, 12:19 PM
#7
It can be hard (or if not I don't knwo how) to control the physical order of the nodes but IDs can be ordered easy enough. I believe there is an Insert or InsertAt method that you can use to try and control the physical order. Primarily what is reserved is the hierarchy structure, child to parent and so on. Really the key to getting tricky with it is learning XPath queries.
http://www.zvon.org/xxl/XPathTutoria.../example1.html
http://www.w3.org/TR/xpath
If you have some sample xml data you can post or upload then I can probably help a little more.
-
Jul 29th, 2003, 12:34 PM
#8
PowerPoster
The DOM Object is a very powerful xml tool. Everything you are describing pertains to retrieving the current node. Once you have a pointer to the node, you add, remove, insert before, after, etc.. I have extensive experience with xml / xslt / dom, so feel free to ask and questions and/or need examples.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|