|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
xml and dotnetget 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> 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. Show quote "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> > 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! Have you tried :
XmlHeaderNode =rootNode.SelectSingleNode("tns:response_header/",nsmgr); Show quote "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! > |
|||||||||||||||||||||||