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

XMLTextReader for Search?

Guys -
I am a rookie to the field of xml but I have a pressing issue that I hope
you can help with.

I have an xml document (say runs.xml). I would like to load it in my Vb .net
app and search for the presence of a certain attribute value. This xml file
would have user information along with their login ID.
How can I use system.xml to read this file and check the existence of an
atrribute value.? Any samples would be appreciated.
Nov 12 '05 #1
3 4767


Siva wrote:
I am a rookie to the field of xml but I have a pressing issue that I hope
you can help with.

I have an xml document (say runs.xml). I would like to load it in my Vb .net
app and search for the presence of a certain attribute value. This xml file
would have user information along with their login ID.
How can I use system.xml to read this file and check the existence of an
atrribute value.? Any samples would be appreciated.


The following is a simple C# command line program reading a value from
the command line and looking for attributes with that value:

using System;
using System.Xml;

public class Test20040221 {
public static void Main (string[] args) {
XmlTextReader xmlReader = new XmlTextReader("test20040221.xml");
while (xmlReader.Read()) {
if (xmlReader.HasAttributes) {
while (xmlReader.MoveToNextAttribute()) {
if (xmlReader.Value == args[0]) {
Console.WriteLine("Found value in attribute named {0}.",
xmlReader.Name);
}
}
}
}
}
}

Hopefully you are able to convert that to VB.NET, you simply need to
check if the current node HasAttributes and then you loop while
MoveToNextAttribute() returns true. Maybe you want to break once you
have found the attribute, the above example however continues to look
for further matches.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #2
this is great . thanks
"Martin Honnen" <Ma***********@t-online.de> wrote in message
news:eD****************@TK2MSFTNGP11.phx.gbl...


Siva wrote:
I am a rookie to the field of xml but I have a pressing issue that I hope you can help with.

I have an xml document (say runs.xml). I would like to load it in my Vb ..net app and search for the presence of a certain attribute value. This xml file would have user information along with their login ID.
How can I use system.xml to read this file and check the existence of an atrribute value.? Any samples would be appreciated.


The following is a simple C# command line program reading a value from
the command line and looking for attributes with that value:

using System;
using System.Xml;

public class Test20040221 {
public static void Main (string[] args) {
XmlTextReader xmlReader = new XmlTextReader("test20040221.xml");
while (xmlReader.Read()) {
if (xmlReader.HasAttributes) {
while (xmlReader.MoveToNextAttribute()) {
if (xmlReader.Value == args[0]) {
Console.WriteLine("Found value in attribute named {0}.",
xmlReader.Name);
}
}
}
}
}
}

Hopefully you are able to convert that to VB.NET, you simply need to
check if the current node HasAttributes and then you loop while
MoveToNextAttribute() returns true. Maybe you want to break once you
have found the attribute, the above example however continues to look
for further matches.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #3
I would think I will have to use this in conjunction wiuth
xmlReader.HasValue right.

Say for example the attribute is sAMAccountName with a value of Martin.
I want to check the value that this attribute has.

Can you clarify please..

Thanks
"Siva" <po******@hotmail.com> wrote in message
news:rtKZb.236437$U%5.1495820@attbi_s03...
Guys -
I am a rookie to the field of xml but I have a pressing issue that I hope
you can help with.

I have an xml document (say runs.xml). I would like to load it in my Vb ..net app and search for the presence of a certain attribute value. This xml file would have user information along with their login ID.
How can I use system.xml to read this file and check the existence of an
atrribute value.? Any samples would be appreciated.

Nov 12 '05 #4

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

Similar topics

0
by: Blink | last post by:
I'm using the XmlTextReader class to parse an XML feed. I need to search for elements that may or may not be there; for example, if there was an error with my request the XML will contain an...
4
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This...
3
by: Michael | last post by:
http://support.microsoft.com/default.aspx?scid=kb;en-us;815658 The page above solved all of my problems with one exception. When the file has strange data in it, possibly Japanese, I get the...
5
by: Geoff Bennett | last post by:
While parsing an XML document, my TextReader instance skips nodes. For example, in this fragment: <Person Sex="Male" FirstHomeBuyer="No" YearsInCurrentProfession="14"> <RelatedEntityRef...
1
by: RJN | last post by:
Hi I'm using XMLTextReader to parse the contents of XML. I have issues when the xml content itself has some special characters like & ,> etc. <CompanyName>Johnson & Jhonson</CompanyName>...
1
by: SHC | last post by:
Hi all, I did the "Build" on the attached code in my VC++ .NET 2003 - Windows XP Pro PC. On the c:\ screen, I got the following: Microsoft Development Environment An unhandled exception of type...
2
by: Q | last post by:
I am feeding XmlTextReader a URL that returns the XML that then gets parsed. The URL forms a query that affects how much data is returned in XML but not the format of the data. The problem is...
2
by: XML reading with XMLTextReader | last post by:
im trying to read an xml file which is in the wwwroot folder.im using IIS on XP Prof. my code is...
4
by: CodeRazor | last post by:
I am trying to use an XmlTextReader to retrieve data. I need to use an XmlTextReader because it is faster than using an XmlDocument. I have found an inelegant way of retrieving each item's title...
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: 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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
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
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...

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.