Solved

how to get the value of an xml document element?

Posted on 2006-07-11
9
1,315 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:viola123
9 Comments
 
LVL 16

Expert Comment

by:Swapnil Piparia
ID: 17080664
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
0
 
LVL 5

Assisted Solution

by:vinodhsomasekharan
vinodhsomasekharan earned 350 total points
ID: 17080680
Hai,

Dim myXmlDoc As New XmlDocument
        Dim myXmlNode As XmlNode

        myXmlDoc.Load(<give u r xml file location/path here..>)

        myXmlNode = myXmlDoc.SelectSingleNode("//connector_ret/function[ @name='contact_create' ]/ret_val[ @name='c_id']" )
       
      myXmlNode.InnerText
u can get the value using   myXmlNode.InnerText  property..


hope this helps

Regards
Vinu
0
 
LVL 6

Accepted Solution

by:
Nandakumar Sakthivel earned 150 total points
ID: 17080682
Hi,

        Dim val As String
        Dim xmldoc As New XmlDocument
        xmldoc.Load("example.xml")
        Dim childElement As XmlElement
        childElement = xmldoc.SelectSingleNode("//connector_ret/function/ret_val")
        If (childElement.GetAttribute("name") = "c_id") Then
            val = childElement.InnerText()
        End If

You can use some thing like this

Hope this helps

Nanda
0
 
LVL 8

Expert Comment

by:kaliyugkaarjun
ID: 17080775
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 6

Author Comment

by:viola123
ID: 17080941
thanks folks!!

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

viola123
0
 
LVL 5

Expert Comment

by:vinodhsomasekharan
ID: 17081027
myXmlDoc.LoadXML(string variable);
0
 
LVL 6

Author Comment

by:viola123
ID: 17081063
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
0
 
LVL 5

Expert Comment

by:vinodhsomasekharan
ID: 17081725
can u post what is the value in result variable?
0
 
LVL 5

Expert Comment

by:vinodhsomasekharan
ID: 17081763
<?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
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
varchar (max) 5 28
SignalR - getting new data from sql DB 5 64
Paging GridView 7 32
JavaScript error 1 33
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now