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
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
</function>
</connector_ret>
who can tell me how to retrieve that 236939 using c# or vb.net?
thanks
viola123
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This tutorial describes well
http://web6.codeproject.com/csharp/csreadxml1.asp
http://web6.codeproject.com/csharp/csreadxml1.asp
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
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);
ASKER
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
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
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
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