473,396 Members | 1,879 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,396 software developers and data experts.

How can I get active attribute value in my Xml and using next() function retrieve the

<?xml version="1.0" encoding="utf-8" ?>
<animals>
<dog num="1">xyz</dog>
<dog num="2">abc</dog>
<dog num="3">qwe</dog>
<dog num="4">tyu</dog>
</animals>

How can I set a current attribute value to a variable i, using this current attribute i when a method next() is called, it should retrieve next node value (for example if current attribute value is 1 when the next() is called it should retrieve 2 attribute value and when again next() is called it should retrieve 3rd attribute value) using System.Xml?

This is what i've done, but with this I can only retrieve next dog node i.e only 2nd attribute.

string BuildXpathQuery(int c) {

string part1 = @"questions/question[@num='";
string part2 = @"']";
string MyQuery = part1 + c + part2;
return MyQuery;

}

// TO retrieve first node value
public void Dog1()
{
XmlDocument doc = new XmlDocument();
doc.Load("C:\\Users\\Murari\\Documents\\Visual Studio 2015\\Projects\\ConsoleApplication14\\ConsoleAppli cation14\\XMLFile1.xml");

XmlNode xnList = doc.SelectSingleNode(BuildXpathQuery(1));
if (xnList != null)
{
Console.WriteLine(xnList.InnerXml);
Console.ReadKey();
}
}

public void Next()
{

}
Jul 9 '16 #1
0 1127

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Jim Geissman | last post by:
Take a table, where not all the columns are populated: CREATE TABLE #T (A int, B int, C int, D int) INSERT #T (A,B) VALUES (1,2) INSERT #T (A,B) VALUES (3,4) INSERT #T (A,B) VALUES (5,6)...
4
by: Dave | last post by:
Hi, I tried something with 'return value' of a function and i got two different behaviours. My question is: why does method 1 not work? Thanks Dave method 1: here, whatever i choose (ok or...
5
by: Mateusz Loskot | last post by:
Hi, I'd like to ask how XML parsers should handle attributes which consists of &quot; entity as value. I know XML allows to use both: single and double quotes as attribute value terminator. That's...
2
by: Greg | last post by:
Hi. I have a rather large xml document (object) that can have one or more nodes with a certain attribute throughout (at ANY depth, not at the same level necessarily). I need to find this...
10
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me,...
1
by: AST | last post by:
Hey, I am struggling with how to form the XPath expression to find the value of an attribute value without case sensitivity. I have tried the following, but I must be missing something simple....
5
by: Oleg.Ogurok | last post by:
Hi there, I need to encode the value of an XML attribute, e.g. string myXml = "<element myAttr=\"" + encodeURIComponent("my \"value") + "\"" ...."; Is there an equivalent of...
5
by: jose1lm | last post by:
What is supposed to happen: A user enters data into one of the FORM input selections. When the user submits the form, the onclick event is supposed to go to a function that will set another FORM...
7
by: Terry Olsen | last post by:
How do I get this to work? It always returns False, even though I can see "This is True!" in the debug window. Do I have to invoke functions differently than subs? Private Delegate Function...
1
by: vbdotnet | last post by:
I want to retrieve a value from a function using return. Like this: Sub Main() dim x as integer = 10 getX(x) 'how do I get z in here? End Sub
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.