473,785 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need some basic help

AGB
Hi all,

I have the following simple XML file. I would like to load all the
values in the Name nodes into a drop-down list box:

<?xml version="1.0" encoding="utf-8" ?>
<OutlineCodeNam es>
<OutlineCodeNam e>
<UID>23423523 </UID>
<Name>Contrac t</Name>
<K234432344/>
</OutlineCodeName >
<OutlineCodeNam e>
<UID>16345345 </UID>
<Name>Project Charge Number</Name>
<K66634535/>
</OutlineCodeName >
</OutlineCodeName s>

Here is the code I am using:

private void PopulateComboBo x()
{
XmlDocument doc = new XmlDocument();
XmlNode rootNode;
XmlNodeList methodNodes;

doc.Load(Applic ation.StartupPa th + @"\PDSTest.xml" );
rootNode = doc.DocumentEle ment;
methodNodes = rootNode.Select Nodes("OutlineC odeName");
cmbMethod.Begin Update();
foreach (XmlNode methodNode in methodNodes)
{
cmbMethod.Items .Add(methodNode .FirstChild.Nex tSibling.Value) ;
}
cmbMethod.EndUp date();

cmbMethod.Selec tedIndex = 0;
}
I am getting nothing back. Any help?

Nov 12 '05 #1
2 1407
1. Define your rootNode as an XmlElement insted of an XmlNode:
XmlElement rootNode;

2. And add to the combobox the InnerXml value:
cmbMethod.Items .Add(methodNode .FirstChild.Nex tSibling.InnerX ml);

Hope this helped.

AGB wrote:
Hi all,

I have the following simple XML file. I would like to load all the
values in the Name nodes into a drop-down list box:

<?xml version="1.0" encoding="utf-8" ?>
<OutlineCodeNam es>
<OutlineCodeNam e>
<UID>23423523 </UID>
<Name>Contrac t</Name>
<K234432344/>
</OutlineCodeName >
<OutlineCodeNam e>
<UID>16345345 </UID>
<Name>Project Charge Number</Name>
<K66634535/>
</OutlineCodeName >
</OutlineCodeName s>

Here is the code I am using:

private void PopulateComboBo x()
{
XmlDocument doc = new XmlDocument();
XmlNode rootNode;
XmlNodeList methodNodes;

doc.Load(Applic ation.StartupPa th + @"\PDSTest.xml" );
rootNode = doc.DocumentEle ment;
methodNodes = rootNode.Select Nodes("OutlineC odeName");
cmbMethod.Begin Update();
foreach (XmlNode methodNode in methodNodes)
{
cmbMethod.Items .Add(methodNode .FirstChild.Nex tSibling.Value) ;
}
cmbMethod.EndUp date();

cmbMethod.Selec tedIndex = 0;
}
I am getting nothing back. Any help?


Nov 12 '05 #2
"AGB" <ag*******@hotm ail.com> wrote in message news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I would like to load all the values in the Name nodes into a drop-down list box: : : <OutlineCodeNam es>
<OutlineCodeNam e>
<UID>23423523 </UID>
<Name>Contrac t</Name> : : methodNodes = rootNode.Select Nodes("OutlineC odeName");


SelectNodes( ) takes a string argument that needs to be an XPath
expression. You receive nothing back because when it processes
the XPath, ''OutlineCodeNa me'', it compares it to the document
element's name only. The document element's name had a trailing
-s, ''OutlineCodeNa mes'', which doesn't match.

If it's the Name grandchild element you want the inner text of, then
you need to write an XPath expression with what are called "location
steps" to reach the Name node. XPath is hierarchical, like your PC's
file system.

Start at the root, /OutlineCodeName s.

From all of the immediate children of OutlineCodeName s, you want
OutlineCodeName elements (and if there were elements with other
names they would be filtered out by this 'step'). This gives you the
XPath, /OutlineCodeName s/OutlineCodeName .

Taking another look at all of the immediate children of OutlineCodeName
(UID, Name, etc.), the element name you want to take in the next step
is Name. This gives you the XPath expression:

/OutlineCodeName s/OutlineCodeName/Name

If you plug that string into what you've passing to SelectNodes( )
you should receive an XmlNodeList with one XmlNode for each
<Name> element.

Then take each <Name> elements' FirstChild.Valu e and Add( )
the names to your DropDown. With the example XML document
this should give you items for ''Contract'' and ''Project Charge
Number''.

Alternately, you could also write the XPath expression this way,

/OutlineCodeName s/OutlineCodeName/Name/text( )

which will return you an XmlNodeList containing XmlText nodes,
from which you can directly take the Value from.

Further, if you're interested in all elements named <Name> you
can get all elements named <Name> no matter where they are
in the document using the descendant-or-self axis, //.

//Name/text( )

The drawback is its not as efficient, and it's less specific about
which <Name> elements it returns (although you can get more
specific, such as //OutlineCodeName/Name/text( ) to ensure it
only returns the text of <Name> elements that are direct children
of <OutlineCodeNam e> -- and get none that are the direct
children of <DraftEditor> .)
Derek Harmon
Nov 12 '05 #3

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

Similar topics

2
4236
by: AK | last post by:
I don't want any part of the previous discussion on Visual Basic versus Visual Basic.Net. My query is about using Visual Basic for Applications; and whether it is better to use Visual Basic 6 or Visual Basic.Net as a springboard for studying VBA. I use Office 2000 and would like to use VBA as a tool to customize it. I have zero programming experience. I would like to read through and work on the examples of a beginners
4
2434
by: Steve Richfie1d | last post by:
I wrote my first BASIC compiler when Bill Gates was going to Lakeside School, and am believed to be the original inventor of the ON ERROR statement. Now, my son wants to learn Visual Basic, but NOT from me. He wants a manual that is NOT a handholding tome on how to write a program, but instead is rather a complete language description in the tradition of the old IBM language manuals. Does this exist? Is there anything like this...
9
2938
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with a device. The definition of the table is as follows: CREATE TABLE devicedata ( device_id int NOT NULL REFERENCES devices(id), -- id in the device
1
2154
by: Tom Rahav | last post by:
Hello all! I develop application in Visual Basic .NET and ORACLE database. My question is how do I "send" script file to the database using visual basic .net. Other words, is there any way to send to the database a script file to run, as done by: "@FullPath\FileName" in SQL PLUS ? If not, then I need your help with something else: I tried to send to the database the script file's content, in order to run the commands in it (create...
13
3035
by: usenet | last post by:
How and where can one find out about the basics of VB/Access2003 syntax? I am a died in the wool C/C++/Java Linux/Unix programmer and I am finding it difficult to understand the program format for accessing objects, controls, etc. in VB/Access2003. In particular where will I find explanations of:- Actions, Functions, Methods, Properties - I'm understand the
4
2214
by: robinsand | last post by:
My apologies to those of you who are more advanced Visual C++ .NET programmers, but I am working on a project for an MBA course that is condensed into an eight-week schedule, and I need help getting a program up and running with proper files and documentation to be handed in for a grade (on Microsoft Visual Studio .NET 2003). I am being graded on how well I incorporate advanced C++ features such as inheritance, polymorphic programming,...
0
893
CLAW
by: CLAW | last post by:
Hi, I'm new with Visual Basic. I've started a Web Browser project in Visual Basic 2005 Express Edition, but being new I really need some help: 1) When the user presses a button, I want to execute an help file in the same directory as the browser, but before to check if the file exists. How can I do that? I also want to execute the Internet Properties form (C:\WINDOWS\system32\inetcpl.cpl for WinXP) 2) Need some help with the progress bar. I...
51
6525
by: Steven Spits | last post by:
Hi, Plannig to buy Vista, but not sure what version to get. I do VS.NET development, mostly ASP.NET. Can IIS be installed on Vista home premium? Or do I need business or ultimate? Steven
4
1394
by: ooroboo | last post by:
i wont a text file to load into a rich text on box on load , then save when the form closes. my problem has been creating the text file , i am very new for visual basic and could use some help this is my attempt on this. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load RichTextBox1.LoadFile("C:\OutputFolder\lol", RichTextBoxStreamType.PlainText) On Error Resume Next...
3
1333
by: shimul | last post by:
Hi All, Have query where I get the result like (except "-------------------",put it to separate the two columns) NUMBER ---------------TYPE DESCRIPTION 17 --------------------------Basic 17 --------------------------Basic 17 --------------------------Actions 17 ---------------------------Conditions 17 ----------------------------Factors
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10330
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10153
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.