Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# WPF
There is a table in which one column is in the form of an xml string,and this string contain another 5 column the xml string is like child table of the first one..i want to access the attribute values in this xml string for checking a search criteria..Tell me please how can i access attributes..Please give me an example code to implement that..
Thanks in advance.
Posted 21-Jan-13 18:37pm
Edited 21-Jan-13 20:26pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This is my short overview of different XML parsing methods you can use:
  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
  3. Use the class System.Xml.XmlTextReader; this is the fastest way of reading, especially is you need to skip some data.
  5. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming.
A C swathi at 22-Jan-13 0:45am
Thanks..can u please explain with an example.
Sergey Alexandrovich Kryukov at 22-Jan-13 1:08am
I don't see why you need more explanation. No, first of all, did you already try any of these API? No? Then why wasting more time?
Try it out, and ask a question if you face any problems. Isn't it fair? After all, you are supposed to do you work be yourself, as you are a software developer.
Sergey Alexandrovich Kryukov at 22-Jan-13 1:48am
OK, if you are a fresher, this is just yet another reason to start diffing into it. And then you will see how. Documentation is rich, with code samples... When I advise it, I know what I say. This is the most effective thing you can do about it. Any additional instructions won't help more, really.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

            string str = "your xml string";
            XDocument document = XDocument.Parse(str);
            var books = document.Descendants("book");
            foreach (XElement item in books)
                var idElement = item.Element("id");
                if (idElement.HasAttributes)
                    XAttribute attr = idElement.Attribute("isPrimaryKey");
                    string attrValue = attr.Value;
<?xml version="1.0" encoding="utf-8"?>
	<id isPrimaryKey="true">3785</id>
        <name>CLR via C#</name>
A C swathi at 23-Jan-13 2:27am
thanks..its working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 335
1 OriginalGriff 209
2 BillWoodruff 170
3 Zoltán Zörgő 165
4 Maciej Los 123
0 OriginalGriff 7,854
1 DamithSL 5,949
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,084
4 Kornfeld Eliyahu Peter 4,539

Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100