473,385 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

XML Creating nodes

Hi there,

just wondering if someone could help me. Ive written some code in
vb.net to create the following xml.

<menu>
<menuItem>
<text>Political Update</text>
</menuItem>
<subMenu />
<menuItem>
<text>sub categoruy 1</text>
<url>1</url>
</menuItem>
<menuItem>
<text>sub categoruy 2</text>
<url>3</url>
</menuItem>
<menuItem>
<text>sub categoruy 3</text>
<url>4</url>
</menuItem>
</menu>

what i actually want to do is to add the 'subMenu' item into the xml
like the following. im not sure whow to do this as im building my xml
up by looping through a couple of datasets.

<menu>
<menuItem>
<text>Political Update</text>
</menuItem>
<subMenu>
<menuItem>
<text>sub categoruy 1</text>
<url>1</url>
</menuItem>
<menuItem>
<text>sub categoruy 2</text>
<url>3</url>
</menuItem>
<menuItem>
<text>sub categoruy 3</text>
<url>4</url>
</menuItem>
<subMenu />
</menu>

any help appreciated

CG

Oct 21 '06 #1
2 6219
i just also want to point out that i sued the following code to create
the element subMenu inthe first piece of XML

objXMLGrandchildNode = oXMLValueDoc.CreateNode("element",
"subMenu", "")
objXMLChildNode.appendChild(objXMLGrandchildNode)

what code is required to create the secont piece of XML ????

Thanks

Colin


csgraham74 wrote:
Hi there,

just wondering if someone could help me. Ive written some code in
vb.net to create the following xml.

<menu>
<menuItem>
<text>Political Update</text>
</menuItem>
<subMenu />
<menuItem>
<text>sub categoruy 1</text>
<url>1</url>
</menuItem>
<menuItem>
<text>sub categoruy 2</text>
<url>3</url>
</menuItem>
<menuItem>
<text>sub categoruy 3</text>
<url>4</url>
</menuItem>
</menu>

what i actually want to do is to add the 'subMenu' item into the xml
like the following. im not sure whow to do this as im building my xml
up by looping through a couple of datasets.

<menu>
<menuItem>
<text>Political Update</text>
</menuItem>
<subMenu>
<menuItem>
<text>sub categoruy 1</text>
<url>1</url>
</menuItem>
<menuItem>
<text>sub categoruy 2</text>
<url>3</url>
</menuItem>
<menuItem>
<text>sub categoruy 3</text>
<url>4</url>
</menuItem>
<subMenu />
</menu>

any help appreciated

CG
Oct 22 '06 #2
csgraham74 wrote:
<menu>
<menuItem>
<text>Political Update</text>
</menuItem>
<subMenu>
<menuItem>
<text>sub categoruy 1</text>
<url>1</url>
</menuItem>
<menuItem>
<text>sub categoruy 2</text>
<url>3</url>
</menuItem>
<menuItem>
<text>sub categoruy 3</text>
<url>4</url>
</menuItem>
<subMenu />
</menu>
Assuming you have a System.Xml.XmlDocument instance or a
System.Xml.XmlDataDocument instance you can do e.g.

Dim Xml_Doc As XmlDocument = New XmlDocument
Xml_Doc.Load("XMLFile1.xml")
Dim SubMenu As XmlNode = _
Xml_Doc.SelectSingleNode("menu/subMenu")
Dim MenuItems As XmlNodeList = _
SubMenu.SelectNodes("following-sibling::node()")
For I As Integer = MenuItems.Count - 1 To 0 Step -1
SubMenu.InsertBefore(MenuItems(I), SubMenu.FirstChild)
Next
' Now save back e.g.
Xml_Doc.Save("XMLFile2.xml")

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jeffrey Silverman | last post by:
Hi, all. I have a linked list. I need an algorithm to create a tree structure from that list. Basically, I want to turn this: $list = array( array( 'id' => 'A', 'parent_id' => null, 'value'...
4
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum...
3
by: NoLongerMicah | last post by:
I have derived new classes for the TreeNode and TreeView classes that Microsoft provides. Since the TreeNodeCollection class is sealed I created my own class that implements the IList interface. ...
4
by: Amit Bhatia | last post by:
User-Agent: OSXnews 2.081 Xref: number1.nntp.dca.giganews.com comp.lang.c++:817424 Hi, I have posted this post also for the thread "vector of lists" but since it is about something else...
5
by: Marcin Gil | last post by:
Hi! I have the code like this (obvious things like ctor/dtor removed) typedef struct _NODE { int val; int index; } Node;
2
by: RickH | last post by:
Using the ms XMLDOM... What techniques do you guys use to create deep elements in code for appending to the main document as the user "adds" complex objects. Currently I keep 3 files to do it...
8
by: arunrocks | last post by:
Hi I am having a requirement to create a db in 2 out of 8 partitiones. I have the following doubts. 1. should I create a new instance in 2 partitions alone (the present instance spans 8 nodes)...
2
by: Polaris431 | last post by:
I need to implement a tree structure that can accept various types of classes or structs. When the tree is created, all of its nodes are based on a single type and not a mixture of types. ...
10
by: John Rogers | last post by:
This code only counts the parent nodes or rootnodes in a treeview, how do you count all the nodes in a treeview? // one way int NodeCounter = 0; foreach (TreeNode currentNode in...
1
by: Sumz | last post by:
what would the syntax be to create new parent and child nodes to an existing tree view. i just need to create text and not link to any where. these nodes would be created at runtime with a button.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.