Zahn Software

Conceive, Believe, Achieve!
  • Email
  • Facebook
  • Linkedin
  • Twitter
  • Rss
Call Now: 1-800-123-4567
  • Home
  • About
    • Clients & Partnerships
    • Philosophy
    • Principles & Practices
  • Contact
    • Partner Agreement Form
  • Design
    • Design Samples
  • Entrepreneurship
  • Web
    • API Development and Integration
    • ASP.NET Web Services Development
    • DotNetNuke Web Development
    • eCommerce
    • Landing Page Development
    • Personal and Small Business Websites
    • Silverlight
    • Telephony Applications
    • Web Application Development
    • Web Multimedia
    • WordPress Development
  • Windows
    • Dashboard and Reporting Services
    • ECM & Document Management
      • Laserfiche
    • WPF, XAML, Windows Forms Development
  • Mobile
    • Native, Web-Base and Hybrid Apps
  • Resources
    • FAQ
    • Glossary

Querying XML Attributes

Posted on November 27, 2010 by Stuart Zahn in General
Home» General » Querying XML Attributes

I’ve been taking XML drills through Inner Working’s online certification. New ways of handling XML data have made it easier than ever. However, there are some pitfalls when querying XML. Below is an example. If you want to get and “ID” attribute from a document element, here is what you might do:

[sourcecode language='csharp']

string documentID;

//Correct: Referencing the “Document Element” variable
documentID = xmldoc.DocumentElement.Attributes["id"].InnerXml;

//Correct: Selecting the “Document” node”
documentID = xmldoc.SelectSingleNode(“document”).Attributes["id"].InnerXml;

//Wrong: Selecting the “Document” node”
documentID = xmldoc.DocumentElement.SelectSingleNode(“document”).Attributes["id"].InnerXml;

[/sourcecode]

Below is the full source

[sourcecode language='csharp']

System.IO.Stream s = this.GetType().Assembly.GetManifestResourceStream (“WindowsFormsApplication1.resources.XMLFile.xml”);
System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument();
xmldoc.Load(s);
s.Close();

string ItemID = xmldoc.SelectSingleNode(“document”).Attributes["id"].InnerXml;
Console.WriteLine(ItemID);

[/sourcecode]


Stuart Zahn is a software developer, blogger, and passionate about personal development. I believe there is intrinsic purpose behind all my work. As a programmer, my purpose is to help your business by delivering better software. I just call it creative indulgence. I try to put personal development and character above career. So, if you want to discuss personal development, partnerships, or job opportunities, please feel free to send me a message anytime.

No related posts.

XML

Comments are closed.

Pages

  • About
    • Clients & Partnerships
    • Philosophy
    • Principles & Practices
  • Contact
    • Partner Agreement Form
  • Design
    • Design Samples
  • Entrepreneurship
  • Web
    • API Development and Integration
    • ASP.NET Web Services Development
    • DotNetNuke Web Development
    • eCommerce
    • Landing Page Development
    • Personal and Small Business Websites
    • Silverlight
    • Telephony Applications
    • Web Application Development
    • Web Multimedia
    • WordPress Development
  • Windows
    • Dashboard and Reporting Services
    • ECM & Document Management
      • Laserfiche
    • WPF, XAML, Windows Forms Development
  • Mobile
    • Native, Web-Base and Hybrid Apps
  • Resources
    • FAQ
    • Glossary

Categories

  • Agile
  • ASP.NET
  • Cloud Computing
  • Document Imaging
  • Document Management
  • DotNetNuke
  • Entrepreneurship
  • General
  • Mobile Development
  • Press Releases
  • Ruby on Rails
  • Social Media
  • Software Development
  • Uncategorized
  • Web Development
  • Windows Development

Tags

.net .NET remoting abbyy Active Directory API architecture ASP.NET authentication Authorization Automation BPO C# Cloud Data Docs DotNetNuke Frameworks Google icr IIS Login Messaging node.js ocr omnipage opentext ORM PHP powershell Press Release scripting scripts Session Social Media Telerik UI User interfaces UX Web Service Websites Windows Windows Services WPF XML Yii

(c) 2012 Zahn Software - Web Design by Jason Bobich