Click here to Skip to main content
15,886,422 members
Home / Discussions / C#
   

C#

 
GeneralRe: DoubleBuffer problem .. Pin
Heath Stewart21-Dec-04 12:38
protectorHeath Stewart21-Dec-04 12:38 
GeneralRe: DoubleBuffer problem .. Pin
Dave Kreskowiak21-Dec-04 16:20
mveDave Kreskowiak21-Dec-04 16:20 
GeneralRe: DoubleBuffer problem .. Pin
Heath Stewart22-Dec-04 6:12
protectorHeath Stewart22-Dec-04 6:12 
GeneralRe: DoubleBuffer problem .. Pin
Dave Kreskowiak22-Dec-04 11:53
mveDave Kreskowiak22-Dec-04 11:53 
GeneralRe: DoubleBuffer problem .. Pin
Skynyrd21-Dec-04 10:44
Skynyrd21-Dec-04 10:44 
GeneralRe: DoubleBuffer problem .. Pin
Sharpoverride22-Dec-04 23:40
Sharpoverride22-Dec-04 23:40 
Generalcalling a function in a subclassed window Pin
stefan houtz21-Dec-04 1:28
stefan houtz21-Dec-04 1:28 
GeneralC# XPath Problems Pin
Chua Wen Ching20-Dec-04 23:00
Chua Wen Ching20-Dec-04 23:00 
Hi,

I read from this tutorial at codeproject

Question A:

http://www.codeproject.com/csharp/GsXPathTutorial.asp

regarding xpath.. but i try to apply in my situation, and can't get it work...

just say this is my xml file:

Device.xml
=========
<?xml version="1.0" encoding="utf-8"?>
<DeviceList xmlns="http://tempuri.org/Device.xsd">
<!-- Device 1 -->
<Device id="1">
<Connection>
<Type>Titan123</Type>
<Open />
<ConfigCard>
<Name>Titan Suprema</Name>
<Length>13</Length>
</ConfigCard>
</Connection>
</Device>
<Device id="2">
<Connection>
<Type>BBB Hardware</Type>
<Open />
<ConfigCard>
<Name>BBB DH</Name>
<Length>6</Length>
</ConfigCard>
</Connection>
</Device>
</DeviceList>

In my C# code,

string devicePath = Application.StartupPath + @"\device.xml";
// open XmlTextReader
...
int nMaxId = 0;

// get maximum devices within XML script
while(xmlDevice.Read())
{
if (xmlDevice.IsStartElement() && xmlDevice.Name == "Device")
{
int nId = Int32.Parse(xmlDevice.GetAttribute("id"));

if (nMaxId < nId)
nMaxId = nId;
}
}
}

// Execute XPath here
XPathDocument xdoc = new XPathDocument(devicePath);
XPathNavigator nav = xdoc.CreateNavigator();

// loop into 2 possible devices and extract particular information
for (int i = 1; i < nMaxId + 1; i++)
{
XPathNodeIterator nodeItor = nav.Select(
"DeviceList/Device[@id='" + i + "']/Connection");
nodeItor.MoveNext();

TraverseChildren(nodeItor);
}
...

// from the article
private void TraverseChildren(XPathNodeIterator nodeItor)
{
XPathNodeIterator igor = nodeItor.Clone();
igor.Current.MoveToFirstChild();
bool more = false;
do
{
PrintNode(igor.Current);
more = igor.Current.MoveToNext();
}while(more);
}

private void PrintNode(XPathNavigator nav)
{
MessageBox.Show("Value: " + nav.Value +
" Type : " + nav.NodeType.ToString());
}

From this solution:

i get this instead:

MessageBox1 - Value: Titan123 Titan Suprema 13BBB Hardware BBB DH 6
MessageBox2 - Value: Titan123 Titan Suprema 13BBB Hardware BBB DH 6
(repeat the same message - why?)

Any help please?

I want to get the Output of this:

MessageBox1 - Value: Titan123 Titan Suprema 13
MessageBox2 - Value: BBB Hardware BBB H 6

Question B:

By the way how can i get the value of individual Type example,

showing the output here:

Type - Titan123
Name - Titan Suprema
Length - 13

i always only manage to get the type which is "Name" and the whole message "Titan123 Titan Suprema 13" instead separate data.

Any help please? Thanks.

Regards,
Chua Wen Ching
Visit us at http://www.necoders.com
GeneralRe: C# XPath Problems Pin
Heath Stewart21-Dec-04 12:36
protectorHeath Stewart21-Dec-04 12:36 
GeneralDisplaying IIS directories/sites in C# Application Pin
Adnan Siddiqi20-Dec-04 22:43
Adnan Siddiqi20-Dec-04 22:43 
GeneralRe: Displaying IIS directories/sites in C# Application Pin
Heath Stewart20-Dec-04 22:53
protectorHeath Stewart20-Dec-04 22:53 
GeneralRe: Displaying IIS directories/sites in C# Application Pin
Adnan Siddiqi21-Dec-04 0:34
Adnan Siddiqi21-Dec-04 0:34 
GeneralRe: Displaying IIS directories/sites in C# Application Pin
Heath Stewart21-Dec-04 7:54
protectorHeath Stewart21-Dec-04 7:54 
GeneralRe: Displaying IIS directories/sites in C# Application Pin
Adnan Siddiqi31-Dec-04 20:13
Adnan Siddiqi31-Dec-04 20:13 
GeneralRe: Displaying IIS directories/sites in C# Application Pin
Heath Stewart31-Dec-04 22:42
protectorHeath Stewart31-Dec-04 22:42 
GeneralRe: Displaying IIS directories/sites in C# Application Pin
Adnan Siddiqi2-Jan-05 19:50
Adnan Siddiqi2-Jan-05 19:50 
GeneralRe: Displaying IIS directories/sites in C# Application Pin
Heath Stewart2-Jan-05 21:14
protectorHeath Stewart2-Jan-05 21:14 
GeneralRe: Displaying IIS directories/sites in C# Application Pin
Adnan Siddiqi3-Jan-05 7:55
Adnan Siddiqi3-Jan-05 7:55 
GeneralRe: Displaying IIS directories/sites in C# Application Pin
Adnan Siddiqi5-Jan-05 8:05
Adnan Siddiqi5-Jan-05 8:05 
GeneralSQL statement with result list restriction Pin
ppp00120-Dec-04 22:25
ppp00120-Dec-04 22:25 
GeneralRe: SQL statement with result list restriction Pin
Colin Angus Mackay20-Dec-04 22:45
Colin Angus Mackay20-Dec-04 22:45 
GeneralGDI+ nonrectangular forms problem Pin
sstoyan20-Dec-04 22:18
sstoyan20-Dec-04 22:18 
GeneralRe: GDI+ nonrectangular forms problem Pin
Heath Stewart20-Dec-04 22:45
protectorHeath Stewart20-Dec-04 22:45 
GeneralRe: GDI+ nonrectangular forms problem Pin
sstoyan21-Dec-04 3:33
sstoyan21-Dec-04 3:33 
GeneralRe: GDI+ nonrectangular forms problem Pin
Heath Stewart21-Dec-04 8:16
protectorHeath Stewart21-Dec-04 8:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.