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

Getting to an attribute.

I have a service that I call that returns back a XmlNode type. I need to get
to an attribute value and would like to use the GetAttribute method (because
it takes a string). However, XmlNode (or XmlElement) does not have that
method. They have the attributes collection with the item method that takes
an number value performing an ordinal lookup. I can declare an Xml document,
load the returning Xml stream, and then use the method but I do not want
reload the document again. Is there a way to take the current document typed
as an XmlNode and get to the document element that has this method without
reloading the stream?

Thanks
Nov 12 '05 #1
4 3922
>However, XmlNode (or XmlElement) does not have that method.
If you are sure that the node is an element, you can cast it to
XmlElement and call XmlElement.GetAttribute or
XmlElement.GetAttributeNode method.
They have the attributes collection with the item method that takes
an number value performing an ordinal lookup Isn't it true that XmlNode.Attributes has overloaded versions to take
either index and name as its argument?
Is there a way to take the current document typed
as an XmlNode and get to the document element that has this method without
reloading the stream?

You can use XmlNode.OwnerDocument.DocumentElement.

------
Thi - http://thith.blogspot.com

Nov 12 '05 #2


Robert Strickland wrote:
I have a service that I call that returns back a XmlNode type. I need to get
to an attribute value and would like to use the GetAttribute method (because
it takes a string). However, XmlNode (or XmlElement) does not have that
method.


XmlNode is indeed a base class that does not implement GetAttribute as
not all nodes have attributes. But XmlElement of course implements
GetAttribute:
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlElementClassGetAttributeTopic.asp >

So in C# if you have
XmlNode someNode;
you can cast if possible e.g.
XmlElement elementNode = someNode as XmlElement;
if (elementNode != null) {
// now access element.GetAttribute here
}

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #3
Casting worked. Thanks

"Truong Hong Thi" <th*****@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
However, XmlNode (or XmlElement) does not have that method.

If you are sure that the node is an element, you can cast it to
XmlElement and call XmlElement.GetAttribute or
XmlElement.GetAttributeNode method.
They have the attributes collection with the item method that takes
an number value performing an ordinal lookup

Isn't it true that XmlNode.Attributes has overloaded versions to take
either index and name as its argument?
Is there a way to take the current document typed
as an XmlNode and get to the document element that has this method without
reloading the stream?

You can use XmlNode.OwnerDocument.DocumentElement.

------
Thi - http://thith.blogspot.com

Nov 12 '05 #4
Casting worked. Thanks

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:eN*************@TK2MSFTNGP10.phx.gbl...


Robert Strickland wrote:
I have a service that I call that returns back a XmlNode type. I need to
get to an attribute value and would like to use the GetAttribute method
(because it takes a string). However, XmlNode (or XmlElement) does not
have that method.


XmlNode is indeed a base class that does not implement GetAttribute as not
all nodes have attributes. But XmlElement of course implements
GetAttribute:
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlElementClassGetAttributeTopic.asp >

So in C# if you have
XmlNode someNode;
you can cast if possible e.g.
XmlElement elementNode = someNode as XmlElement;
if (elementNode != null) {
// now access element.GetAttribute here
}

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Nov 12 '05 #5

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

Similar topics

2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
4
by: Kevin | last post by:
I have a document, lets say: <Doc> <Ele1 Att1='hello'> <Ele2 Att2='goodbye'/> </Ele1> </Doc> In XSLT I need to generate an attribute value which contains part of this document as a text...
0
by: Alexander | last post by:
Please, excuse me if the question is a basic one but I have not found any hint neither on XML4C samples, nor on Apache site. I'm using XML4C. I'm parsing an xml file and I'm getting to an attribute...
5
by: Don | last post by:
Hi: I have created an xsd from my xml document. I pop this xsd in the following directory: C:\program files\Microsoft Visual Studio .NET 2003\Common7\Packages\schemas\xml. That give me...
2
by: Hitesh | last post by:
Hi, I am getting the response from another Website by using the HttpHandler in my current site. I am getting the page but all the images on that page are not appearing only placeholder are...
3
by: Hitesh | last post by:
Hi, I am getting the response from another Website by using the HttpHandler in my current site. I am getting the page but all the images on that page are not appearing only placeholder are...
0
by: rautsmita | last post by:
hello friends , i am using to jdk6 and JAXB2.0, i have geomtry.xsd file i am trying to compile this file using jaxb but i got some error i.e.The particle of the type is not a valid restriction of...
3
by: =?Utf-8?B?WmlhbmdpIEpvbmVz?= | last post by:
Hi, I m using VS .NET 2003 to create a website. Using the setup package I create a setup as well. But this setup has files with actual code in it & not pre-compiled DLLs. Please let me know...
1
by: Chris White | last post by:
Here's my XML <?xml version="1.0" encoding="UTF-8"?> <results> <status code="ok"/> <report-bulk-users> <row principal-id="23859115" type="user"> <login>muser@domain.com</login> <name>My...
0
by: buntyindia | last post by:
Hi, I have a very strange problem with my application. I have developed it using Struts. I have a TextBox With Some fixed value in it and on Submit iam passing it to another page. <html:form...
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?
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:
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.