|
 |
aspx thread: How do I get an attribute value from an xml document
Message #1 by chadm@d... on Wed, 10 Jul 2002 20:27:08
|
|
How do I get a specific (/node1/node2/@name) attribute value from an xml
document. Please help... I have been working on this for three days and
can not understand how this is done. Hey Wrox people, why didn't you put
this example in one of your books?
Message #2 by Feduke Cntr Charles R <FedukeCR@m...> on Wed, 10 Jul 2002 15:29:11 -0400
|
|
Okay, I meant to answer this one earlier this morning, but got side trekked.
using System.Xml;
XmlDocument doc = new XmlDocument();
doc.LoadXml = "your Xml";
// you could doc.Load(fileName); if you want
XmlNode yay = doc.SelectSingleNode("/note1/note2");
// yes, there is a SelectNodes(string XPath) for a collection of XmlNodes
Console.WriteLine("@name: {0}", yay.Attributes["name"]);
HTH,
- Chuck
-----Original Message-----
From: chadm@d... [mailto:chadm@d...]
Sent: Wednesday, July 10, 2002 4:27 PM
To: ASP+
Subject: [aspx] How do I get an attribute value from an xml document
How do I get a specific (/node1/node2/@name) attribute value from an xml
document. Please help... I have been working on this for three days and
can not understand how this is done. Hey Wrox people, why didn't you put
this example in one of your books?
Message #3 by "Chadrick" <chadm@d...> on Wed, 10 Jul 2002 15:44:30 -0400
|
|
Very cool, thanks Chuck - Just one more thing. How do I put the value
into a variable instead of writing it out to the console?
I tried this:
message += node.Attributes["name"]; //didn't work
And where did you find the XmlDocument.SelectSingleNode() method? I am
searching all my books (lots of them) and even the Class Browser doesn't
have it listed. Is there a resource that has everything? I thought the
class browser was suppose to?
Chadrick Mahaffey
-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Wednesday, July 10, 2002 3:29 PM
To: ASP+
Subject: [aspx] RE: How do I get an attribute value from an xml document
Okay, I meant to answer this one earlier this morning, but got side
trekked.
using System.Xml;
XmlDocument doc = new XmlDocument();
doc.LoadXml = "your Xml";
// you could doc.Load(fileName); if you want
XmlNode yay = doc.SelectSingleNode("/note1/note2");
// yes, there is a SelectNodes(string XPath) for a collection of
XmlNodes
Console.WriteLine("@name: {0}", yay.Attributes["name"]);
HTH,
- Chuck
-----Original Message-----
From: chadm@d... [mailto:chadm@d...]
Sent: Wednesday, July 10, 2002 4:27 PM
To: ASP+
Subject: [aspx] How do I get an attribute value from an xml document
How do I get a specific (/node1/node2/@name) attribute value from an xml
document. Please help... I have been working on this for three days and
can not understand how this is done. Hey Wrox people, why didn't you put
this example in one of your books?
Message #4 by "Chadrick" <chadm@d...> on Wed, 10 Jul 2002 16:19:56 -0400
|
|
OH YEAH!!!!!!!
-------------------
string strCurrentPath = Request.PhysicalPath;
strCurrentPath = strCurrentPath.Substring(0,
strCurrentPath.LastIndexOf("\\") + 1);
strCurrentPath += "login278993b.xml";
XmlDocument doc = new XmlDocument();
doc.Load(strCurrentPath);
XmlNode node
doc.SelectSingleNode("/specials_engine_users/organization");
message += node.Attributes["name"].Value;
-------------------
IT WORKS - IT WORKS - WOOHOOO!!!!
Thank you very much Chuck for pointing me in the right direction.
-----Original Message-----
From: Chadrick [mailto:chadm@d...]
Sent: Wednesday, July 10, 2002 3:45 PM
To: ASP+
Subject: [aspx] RE: How do I get an attribute value from an xml document
Very cool, thanks Chuck - Just one more thing. How do I put the value
into a variable instead of writing it out to the console?
I tried this:
message += node.Attributes["name"]; //didn't work
And where did you find the XmlDocument.SelectSingleNode() method? I am
searching all my books (lots of them) and even the Class Browser doesn't
have it listed. Is there a resource that has everything? I thought the
class browser was suppose to?
Chadrick Mahaffey
-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Wednesday, July 10, 2002 3:29 PM
To: ASP+
Subject: [aspx] RE: How do I get an attribute value from an xml document
Okay, I meant to answer this one earlier this morning, but got side
trekked.
using System.Xml;
XmlDocument doc = new XmlDocument();
doc.LoadXml = "your Xml";
// you could doc.Load(fileName); if you want
XmlNode yay = doc.SelectSingleNode("/note1/note2");
// yes, there is a SelectNodes(string XPath) for a collection of
XmlNodes
Console.WriteLine("@name: {0}", yay.Attributes["name"]);
HTH,
- Chuck
-----Original Message-----
From: chadm@d... [mailto:chadm@d...]
Sent: Wednesday, July 10, 2002 4:27 PM
To: ASP+
Subject: [aspx] How do I get an attribute value from an xml document
How do I get a specific (/node1/node2/@name) attribute value from an xml
document. Please help... I have been working on this for three days and
can not understand how this is done. Hey Wrox people, why didn't you put
this example in one of your books?
Message #5 by Feduke Cntr Charles R <FedukeCR@m...> on Thu, 11 Jul 2002 09:07:21 -0400
|
|
Chad,
Ah, you'll probably want to .ToString() it.
message += node.Attributes["name"].ToString();
If you're += a string you should use a System.Text.StringBuilder.
MSDN is probably the only reference you'll need for .NET. Just type
in the namespace and the object and you get an "About BlahBlah" and
"BlahBlah's Members" which are indispensible tools in figuring out problems.
In this case I just looked around the System.Xml namespace in the help until
I figured out how to do it (a few days ago).
- Chuck
-----Original Message-----
From: Chadrick [mailto:chadm@d...]
Sent: Wednesday, July 10, 2002 3:45 PM
To: ASP+
Subject: [aspx] RE: How do I get an attribute value from an xml document
Very cool, thanks Chuck - Just one more thing. How do I put the value
into a variable instead of writing it out to the console?
I tried this:
message += node.Attributes["name"]; //didn't work
And where did you find the XmlDocument.SelectSingleNode() method? I am
searching all my books (lots of them) and even the Class Browser doesn't
have it listed. Is there a resource that has everything? I thought the
class browser was suppose to?
Chadrick Mahaffey
-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Wednesday, July 10, 2002 3:29 PM
To: ASP+
Subject: [aspx] RE: How do I get an attribute value from an xml document
Okay, I meant to answer this one earlier this morning, but got side
trekked.
using System.Xml;
XmlDocument doc = new XmlDocument();
doc.LoadXml = "your Xml";
// you could doc.Load(fileName); if you want
XmlNode yay = doc.SelectSingleNode("/note1/note2");
// yes, there is a SelectNodes(string XPath) for a collection of
XmlNodes
Console.WriteLine("@name: {0}", yay.Attributes["name"]);
HTH,
- Chuck
-----Original Message-----
From: chadm@d... [mailto:chadm@d...]
Sent: Wednesday, July 10, 2002 4:27 PM
To: ASP+
Subject: [aspx] How do I get an attribute value from an xml document
How do I get a specific (/node1/node2/@name) attribute value from an xml
document. Please help... I have been working on this for three days and
can not understand how this is done. Hey Wrox people, why didn't you put
this example in one of your books?
Message #6 by Feduke Cntr Charles R <FedukeCR@m...> on Thu, 11 Jul 2002 09:08:55 -0400
|
|
> message += node.Attributes["name"].Value;
Oh yeah, I guess .ToString() (System.Xml.NodeType or whatever it is)
probably wouldn't work too well.
You're welcome!
- Chuck
-----Original Message-----
From: Chadrick [mailto:chadm@d...]
Sent: Wednesday, July 10, 2002 4:20 PM
To: ASP+
Subject: [aspx] RE: How do I get an attribute value from an xml document
OH YEAH!!!!!!!
-------------------
string strCurrentPath = Request.PhysicalPath;
strCurrentPath = strCurrentPath.Substring(0,
strCurrentPath.LastIndexOf("\\") + 1);
strCurrentPath += "login278993b.xml";
XmlDocument doc = new XmlDocument();
doc.Load(strCurrentPath);
XmlNode node
doc.SelectSingleNode("/specials_engine_users/organization");
message += node.Attributes["name"].Value;
-------------------
IT WORKS - IT WORKS - WOOHOOO!!!!
Thank you very much Chuck for pointing me in the right direction.
-----Original Message-----
From: Chadrick [mailto:chadm@d...]
Sent: Wednesday, July 10, 2002 3:45 PM
To: ASP+
Subject: [aspx] RE: How do I get an attribute value from an xml document
Very cool, thanks Chuck - Just one more thing. How do I put the value
into a variable instead of writing it out to the console?
I tried this:
message += node.Attributes["name"]; //didn't work
And where did you find the XmlDocument.SelectSingleNode() method? I am
searching all my books (lots of them) and even the Class Browser doesn't
have it listed. Is there a resource that has everything? I thought the
class browser was suppose to?
Chadrick Mahaffey
-----Original Message-----
From: Feduke Cntr Charles R [mailto:FedukeCR@m...]
Sent: Wednesday, July 10, 2002 3:29 PM
To: ASP+
Subject: [aspx] RE: How do I get an attribute value from an xml document
Okay, I meant to answer this one earlier this morning, but got side
trekked.
using System.Xml;
XmlDocument doc = new XmlDocument();
doc.LoadXml = "your Xml";
// you could doc.Load(fileName); if you want
XmlNode yay = doc.SelectSingleNode("/note1/note2");
// yes, there is a SelectNodes(string XPath) for a collection of
XmlNodes
Console.WriteLine("@name: {0}", yay.Attributes["name"]);
HTH,
- Chuck
-----Original Message-----
From: chadm@d... [mailto:chadm@d...]
Sent: Wednesday, July 10, 2002 4:27 PM
To: ASP+
Subject: [aspx] How do I get an attribute value from an xml document
How do I get a specific (/node1/node2/@name) attribute value from an xml
document. Please help... I have been working on this for three days and
can not understand how this is done. Hey Wrox people, why didn't you put
this example in one of your books?
|
|
 |