473,804 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3944
>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.GetA ttribute or
XmlElement.GetA ttributeNode 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.Attribu tes 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.OwnerDo cument.Document Element.

------
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/frlrfSystemXmlX mlElementClassG etAttributeTopi c.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.GetAttr ibute 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******** *************@z 14g2000cwz.goog legroups.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.GetA ttribute or
XmlElement.GetA ttributeNode 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.Attribu tes 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.OwnerDo cument.Document Element.

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

Nov 12 '05 #4
Casting worked. Thanks

"Martin Honnen" <ma*******@yaho o.de> wrote in message
news:eN******** *****@TK2MSFTNG P10.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/frlrfSystemXmlX mlElementClassG etAttributeTopi c.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.GetAttr ibute 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
9604
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, while an instance of class C should be able to check all methods #defined in C, B and A. #------------------------------------------------
4
3155
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 string, ie:
0
1165
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 which is not explicitly specified in the xml file. The parser brings me its default value specified in DTD (if any) as the attribute's value. The question is: How do I get the default value if the attribute explicitly appears in the xml file...
5
2163
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 intellisense when I specify the name space. But leaving hte namespace in messes up my transforms. Is there any way to get this intellisense functionality without adding the namespace all the time? Thanks,
2
1709
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 displayed. Can anybody know this issue and help me to resolve this. -- Thanks Hitesh
3
3096
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 displayed. Can anybody know this issue and help me to resolve this. In past i received the response saying that i should download the image first and then parse the actual response and modify the src attribute of the
0
2635
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 the particle of the base this xsd file is valid as per w3c standard i am also providing error in detail and geometry.xsd file geometry.xsd <?xml version="1.0" encoding="UTF-8"?> <schema targetNamespace="http://www.opengis.net/gml"...
3
1930
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 what needs to be done to ensure that DLLs are produced & not code files. Note: BOTH 'codebehind' & 'SRC' attribute has been used. --
1
2617
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 User</name> <email>myuser@domain.com</email> <manager>manager@domain.com</manager>
0
2926
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 action="/login"> <html:text property="userName" value="Bunty"/> <html:submit/>
0
9711
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9591
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10594
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10331
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9166
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.