Link to home
Start Free TrialLog in
Avatar of viola123
viola123

asked on

how to get the value of an xml document element?

hi,

i have an xml document and need to retrieve the value of a particular node. any one can tell me a neat way to retrieve it?

the xml document is as below:
<?xml version="1.0" encoding="UTF-8"?>
<connector_ret>
   <function name="contact_create">
      <ret_val name="c_id" type="integer">236939</ret_val>
   </function>
</connector_ret>


who can tell me how to retrieve that 236939 using c# or vb.net?

thanks
viola123
Avatar of Swapnil
Swapnil
Flag of India image

Hi viola123,
the best way is to write a code ti Querying XML Data with XQuery method in asp.net. You can get help from following article for how to do it.

http://aspnet.4guysfromrolla.com/articles/071603-1.aspx 


Regards,
NetSwap
SOLUTION
Avatar of vinodhsomasekharan
vinodhsomasekharan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kaliyugkaarjun
kaliyugkaarjun

Avatar of viola123

ASKER

thanks folks!!

but my xml is actually returned as a string. is there any way to load this xml string into xmldocument object?

viola123
myXmlDoc.LoadXML(string variable);
thanks vinodhsomasekharan :-)

but it does work here, the error msg is as below:

Unexpected XML declaration. The XML declaration must be the first node in the document, and no white space characters are allowed to appear before it. Line 2, position 3.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Xml.XmlException: Unexpected XML declaration. The XML declaration must be the first node in the document, and no white space characters are allowed to appear before it. Line 2, position 3.

Source Error:


Line 66:
Line 67:         XmlDocument xmldoc = new XmlDocument();
Line 68:         xmldoc.LoadXml(result);

 
//////////////////////
any comments??

thanks
can u post what is the value in result variable?
<?xml version="1.0" encoding="UTF-8"?>
the above line must be the very first line in the xmlstring "result"

ensure that there are no white spaces before or in the first line..

hope it helps u.

Regards
Vinodh