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

xml and dotnet

I have a following xml, i am new to dotnet. can anyone tell me how to
get the attribute date_time from the response_header node using C#

XMl is as follows

<response_info_main xmlns="http://tempuri.org/Response.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Response.xsd">
<response_header date_time="11/17/2004 18:33:33"
number_of_accounts="3" />
<account_list>
/*cust is signing up for 2 new els and 1 with a virtual number too*/
<account account_id="123123" status="PENDING">
<ani_list>
<ani ani="7189782987" status="PENDING">
<response_list>
<response action_id="407" pon="IDT1234569" ver="AA"
sent_date="mm/dd/yyyy hh24:mi:ss" action_description="" error_code=""
/>
<response action_id="404" pon="IDT1234569" ver="AA"
sent_date="mm/dd/yyyy hh24:mi:ss" action_description=""
virtual_number="1111111111" error_code="1234" error_message="Some
error message" />
</response_list>
</ani>
<ani ani="7189782988" status="PENDING">
<response_list>
<response action_id="407" pon="IDT1234569" ver="AA"
sent_date="mm/dd/yyyy hh24:mi:ss" action_description="" error_code=""
/>
</response_list>
</ani>
</ani_list>
</account>
/*one els on this account is canceled yet cust has another one that
is active*/
<account account_id="123123" status="ACTIVE">
<ani_list>
<ani ani="7189782987" status="CANCEL">
<response_list>
<response action_id="201" pon="IDT1234569" ver="AA"
sent_date="mm/dd/yyyy hh24:mi:ss" action_description="" error_code=""
/>
</response_list>
</ani>
</ani_list>
</account>
/*the account has been put into suspend state*/
<account account_id="123123" status="SUSPEND">
<ani_list>
<ani ani="2129782990" status="SUSPEND">
<response_list>
<response action_id="103" pon="IDT1234569" ver="AA"
sent_date="mm/dd/yyyy hh24:mi:ss" action_description="" error_code=""
/>
</response_list>
</ani>
</ani_list>
</account>
</account_list>
</response_info_main>
Nov 12 '05 #1
3 5700
After loading the XML document use SelectNodes or SelectSingleNode to return
an XmlNode refering to your response_header. Then use the Attributes
collection with the string based indexer
(node.Attributes["date_time"].InnerText) to return the contents of the
date_time attribute.

"Venkat Chellam" wrote:
I have a following xml, i am new to dotnet. can anyone tell me how to
get the attribute date_time from the response_header node using C#

XMl is as follows

<response_info_main xmlns="http://tempuri.org/Response.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Response.xsd">
<response_header date_time="11/17/2004 18:33:33"
number_of_accounts="3" />
<account_list>
/*cust is signing up for 2 new els and 1 with a virtual number too*/
<account account_id="123123" status="PENDING">
<ani_list>
<ani ani="7189782987" status="PENDING">
<response_list>
<response action_id="407" pon="IDT1234569" ver="AA"
sent_date="mm/dd/yyyy hh24:mi:ss" action_description="" error_code=""
/>
<response action_id="404" pon="IDT1234569" ver="AA"
sent_date="mm/dd/yyyy hh24:mi:ss" action_description=""
virtual_number="1111111111" error_code="1234" error_message="Some
error message" />
</response_list>
</ani>
<ani ani="7189782988" status="PENDING">
<response_list>
<response action_id="407" pon="IDT1234569" ver="AA"
sent_date="mm/dd/yyyy hh24:mi:ss" action_description="" error_code=""
/>
</response_list>
</ani>
</ani_list>
</account>
/*one els on this account is canceled yet cust has another one that
is active*/
<account account_id="123123" status="ACTIVE">
<ani_list>
<ani ani="7189782987" status="CANCEL">
<response_list>
<response action_id="201" pon="IDT1234569" ver="AA"
sent_date="mm/dd/yyyy hh24:mi:ss" action_description="" error_code=""
/>
</response_list>
</ani>
</ani_list>
</account>
/*the account has been put into suspend state*/
<account account_id="123123" status="SUSPEND">
<ani_list>
<ani ani="2129782990" status="SUSPEND">
<response_list>
<response action_id="103" pon="IDT1234569" ver="AA"
sent_date="mm/dd/yyyy hh24:mi:ss" action_description="" error_code=""
/>
</response_list>
</ani>
</ani_list>
</account>
</account_list>
</response_info_main>

Nov 12 '05 #2
I am doing this as follows, the second select single node call doesn't
return anything for me.

Is that something to do with namespace i am using in xmlns field?
venky

XmlDataDocument doc = new XmlDataDocument();
doc.Load(strFileName);

// following code is temperory, will be removed
//doc.Load(strFileName);

// get header information
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("tns", "http://tempuri.org/Response.xsd");

//Select the book node with the matching attribute value.
XmlNode XmlHeaderNode,XmlRootNode;
XmlNode root = doc.DocumentElement;

XmlNode rootNode = doc.SelectSingleNode("/tns:response_info_main",
nsmgr);
XmlHeaderNode =rootNode.SelectSingleNode("response_header");
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3
Have you tried :

XmlHeaderNode =rootNode.SelectSingleNode("tns:response_header/",nsmgr);
"venkat chellam" wrote:
I am doing this as follows, the second select single node call doesn't
return anything for me.

Is that something to do with namespace i am using in xmlns field?
venky

XmlDataDocument doc = new XmlDataDocument();
doc.Load(strFileName);

// following code is temperory, will be removed
//doc.Load(strFileName);

// get header information
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("tns", "http://tempuri.org/Response.xsd");

//Select the book node with the matching attribute value.
XmlNode XmlHeaderNode,XmlRootNode;
XmlNode root = doc.DocumentElement;

XmlNode rootNode = doc.SelectSingleNode("/tns:response_info_main",
nsmgr);
XmlHeaderNode =rootNode.SelectSingleNode("response_header");
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #4

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

Similar topics

1
by: GChong | last post by:
Hi, Im looking for some general 'marketing' info on dotnet: how long it has been in use (i.e first release date), how many companies are using it, number of .NET developers in the world,...
12
by: tmb | last post by:
1 - Is Microsoft dotnet a Virtual Machine... like the Java Virtual Machine... that will run on any operating system? 2 - If so, does Microsoft give away the dotnet development system like Sun...
5
by: David | last post by:
Hi everyone, I have a ActiveX EXE component written in VB6. This ActiveX EXE exposes various public methods that can be called by several other independent Windows EXE applications (also written...
0
by: Justin Kennedy | last post by:
Hi, I'm new to dotnet. In fact, I'm a Java/web dev. guy mostly. I was debating on whether to use Java or dotnet for a recent project. The main requirements are: 1. Tools to create a "rich"...
10
by: Darren | last post by:
OK, I'm trying to understand the need for this. If I understand correctly without this anyone can reverse engineer and obtain the source code of my application - is this correct? And this tool will...
0
by: Joe Bloggs | last post by:
Hi all, I take the pleasure to inform that Dotnet Commons Logging has been released for use. Dotnet Commons Logging, a subproject of the Donet Commons project currently located under the...
4
by: Peter Hemmingsen | last post by:
Hi, I have a dotnet object (implemented in mc++ and used in c#) which have a property called "Info". The Info property is also a dotnet object (implemented in mc++). In the constructor of the...
4
by: Peter Plumber | last post by:
OK, this is a rather strange request Is it possible to use dot-net dlls in VB6 projects? Is anyone doing this or is this completely useless? thx Peter
3
by: gg | last post by:
My standard version of dotnet 2003 basic does Not have vbc.exe have class library template produce dll when outputtype is changed to classlib for .vbproj it seems that standard version is not...
7
by: Peted | last post by:
Hi, im hoping someone cane provide or point to a definitive accurate explantion of dotnet compilation when run and the best way to optimise peformace when dotnet code is run first time and...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...

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.