How to parse individual fields/elements within XML string from Cli

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • KarenS

    How to parse individual fields/elements within XML string from Cli

    I am using Microsoft Developer Environment 2003 Version 7.1.3088 and .NET
    Framework version 1.1.4322 SP1.

    From my web-service I get one row of data and return it to my client. From
    my client I want to be able to parse apart the Data in the returned XML
    string by field name. (<group_name>, <city>, <state?, etc.) Thank-you.

    More details follow:

    (The Data set is sent to the client from the web-service with .GetXML, see
    below in SECTION 1.)

    When I test my web-service, I see my data as I expect with XML wrapped
    around each data item. See SECTION 2 below. From my client side, when I
    load the data into a label to display the data, I see the data only without
    the XML code, but I think that is because the list box is handling the XML
    and just displaying the data. (If I write a script to display each character
    in my lblMessage.text , I do see all the XML stuff around my data.) See
    SECTION 3 below for how it looks in the label. All I want to be able to do
    in my client application is parse apart the Data by name. (i.e. access the
    <email_addres s> element and get the result and see the result
    TestEmail@Anywh ere.com or access the <group_name> element and get the result.
    It seems like I should somehow be able to just access the XML and say I
    want this element of the data, but I can’t find the syntax anywhere.

    I’ve gone through examples on Microsoft.com, some tutorials and books, but
    they all seem to either not work, or only return one item in the list, which
    is too simplistic. Can someone point me in the correct direction? Thank-you.



    SECTION 1. - Web Method to Get data and return it

    <WebMethod()> _
    Public Function srDAL_GetBroker DataByGroup(ByV al groupId As String) As
    String

    groupId = groupId.Trim

    OleDbConnection Reporting_PROD. Open()
    OleDbCommandRep orting_PROD.Com mandText = "Select * from
    srDAL_Brokers where group_id = '" + groupId + "'"
    OleDbDataAdapte rReporting_PROD .SelectCommand =
    OleDbCommandRep orting_PROD
    OleDbDataAdapte rReporting_PROD .Fill(DataSet_s rDAL_Brokers,
    "srDAL_Brokers" )
    OleDbConnection Reporting_PROD. Close()
    Return DataSet_srDAL_B rokers.GetXml

    End Function

    SECTION 2 – What I see when testing the service in The web-service application

    <?xml version="1.0" encoding="utf-8" ?>
    <string
    xmlns="http://tempuri.org/DDPWAsalesRepor tingDAL/ServiceSalesRep ortingDAL"><Dat aSet_srDAL_Brok ers
    xmlns="http://www.tempuri.org/DataSet1.xsd"> <srDAL_Broker s>
    <group_gid>32 </group_gid> <group_number>1 40</group_number>
    <sublocation_nu mber>0</sublocation_num ber> <group_name>M Y TEST
    GROUP</group_name> <contact_gid>10 0</contact_gid>
    <demographic_gi d>200</demographic_gid >
    <effective_date >2004-07-01T00:00:00.000 0000-07:00</effective_date>
    <termination_da te>9999-12-31T00:00:00.000 0000-08:00</termination_dat e>
    <email_address> TestEmail@anywh ere.com</email_address>
    <phone_number>9 995551212</phone_number> <extension> </extension>
    <other_phone_nu mber>0000000000 </other_phone_num ber>
    <fax_number>999 5551212</fax_number> <salutation_nam e> </salutation_name >
    <name_prefix> </name_prefix> <first_name>JOH N</first_name>
    <last_name>SMIT H</last_name> <middle_name> </middle_name> <name_suffix>
    </name_suffix> <actual_ssn>000 000000</actual_ssn> <gender>M</gender>
    <hipaa_id> </hipaa_id> <business_name> TEST BUSINESS</business_name>
    <address_1>1234 5 MAIN STREET</address_1> <address_2>SUIT E A</address_2>
    <city>ANY CITY USA</city> <state>XX</state> <zip_code>999 99-1234</zip_code>
    <country>USA </country> <group_id>00140 </group_id> </srDAL_Brokers>
    </DataSet_srDAL_B rokers></string>

    SECTION 3 – What I see from my client side when I call the service and put
    the data in a label. This is how the data looks in lblMessage.text

    32 140 0 MY TEST GROUP 100 200 2004-07-01T00:00:00.000 0000-07:00
    9999-12-31T00:00:00.000 0000-08:00 TestEmail@anywh ere.com 9995551212
    0000000000 9995551212 JOHN SMITH 000000000 M TEST BUSINESS 12345 MAIN STREET
    SUITE A ANY CITY USA XX 99999-1234 USA 00140

    SECTION 4 – The code on the client side.

    Private Sub btnGetBrokerByG roupId_Click(By Val sender As System.Object,
    ByVal e As System.EventArg s) Handles btnGetBrokerByG roupId.Click

    Dim groupId As String
    Dim x As Integer
    Dim y As String


    groupId = "00140"
    Dim GB As New
    SalesReportingD ALgetBrokerByGr oupId.ServiceSa lesReportingDAL
    lblMessage.Text = GB.srDAL_GetBro kerDataByGroup( groupId)


    End Sub


Working...