• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

Visual Basic XML Question

Hello Experts - venturing into dangerous territory (for me at least) today.
I'm experimenting with using a web service to go through an XML data set and return a value based on a supplied parameter.  In this case, match a URL to a particular Project
Here's an example of the XML file:
<Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/">
<Result>
<NumberOfRecords>9</NumberOfRecords>
<TotalNumberOfRecords>9</TotalNumberOfRecords>
</Result>
<List>
<Survey>
<Id>18746</Id>
<Name>General Satisfaction</Name>
<SurveyTemplate>
<Id>95</Id>
<Name>General Satisfaction</Name>
</SurveyTemplate>
<Project>
<Id>13542</Id>
<Number>Test123123</Number>
<Name>CompanyName</Name>
</Project>
<StartDate>2012-09-09 00:00:00</StartDate>
<CloseDate>2012-09-23 00:00:00</CloseDate>
<ReminderDate>2012-09-20 00:00:00</ReminderDate>
<ReminderSent>False</ReminderSent>
<AllowInvitingAdditionalPeople>False</AllowInvitingAdditionalPeople>
<Sender>
<Email>email@domain.com</Email>
<FirstName>Mark</FirstName>
<LastName>Fancy</LastName>
</Sender>
<Recipients>
<Recipient>
<Id>9be15d9b-f210-4fb8-94d7-be21eaf49c18</Id>
<Email>email@domain.com</Email>
<FirstName>Mark</FirstName>
<LastName>Fancy</LastName>
<OriginalSender>email@domain.com</OriginalSender>
<Status>Not Started</Status>
<SentOn>2012-09-09 09:12:31</SentOn>
<LastActivityDate/>
<FinishedOn/>
<IsDismissed>False</IsDismissed>
<IsForwarded>False</IsForwarded>
<LinkToSurvey>http://www.CompanyName.com/v20/surveys/take.aspx?ident=9be15d9b-f210-4fb8-94d7-be21eaf49c18</LinkToSurvey>
<EmailSubject>CompanyName</EmailSubject>
<Responses/>
</Recipient>
</Recipients>
<Questions>
<Question>
<Title>How well does our process provide work of appropriate quality?</Title>
<Category>Quality</Category>
<IsCustom>False</IsCustom>
<Order>1</Order>
</Question>
<Question>
<Title>How well does our process help you manage your project budget?</Title>
<Category>Budget</Category>
<IsCustom>False</IsCustom>
<Order>2</Order>
</Question>
</Questions>
<Tags/>
<SentFromGenericEmail>False</SentFromGenericEmail>
<IncludeNPS>False</IncludeNPS>
<InvitationText>Our goal is to constantly provide the highest level of service possible. We recently received feedback from you indicating an opportunity exists for us to improve for you.  Now that we’ve had some time to address the issues, we’d like to check in on how our modified approach is working for you.&lt;br/>&lt;br/>Unlike a generic survey, this request is specific to you, your project, and the team of professionals currently helping meet your project objectives.  Your response will immediately be delivered to the right people, assuring we turn your feedback into better project outcomes for you.&lt;br/>&lt;br/>If you wish to discuss this process or provide feedback personally, please contact us so we may address your concerns.&lt;br/>&lt;br/>Responding to this electronic feedback request should take fewer than 2-3 minutes and is one of the easiest ways you can improve how we help you.</InvitationText>
<ThankYouMessage>Thank you for your feedback!</ThankYouMessage>
</Survey>
<Survey>
<Id>18462</Id>
<Name>One Page Client Satisfaction</Name>
<SurveyTemplate>
<Id>365</Id>
<Name>One Page Client Satisfaction</Name>
</SurveyTemplate>
<Project>
<Id>14133</Id>
<Number>0000020.03</Number>
<Name>Gilbert Elementary School</Name>
</Project>
<StartDate>2012-08-29 00:00:00</StartDate>
<CloseDate>2012-10-15 00:00:00</CloseDate>
<ReminderDate>2000-01-01 00:00:00</ReminderDate>
<ReminderSent>False</ReminderSent>
<AllowInvitingAdditionalPeople>True</AllowInvitingAdditionalPeople>
<Sender>
<Email>feedback@fullsailpartners.com</Email>
<FirstName>Client</FirstName>
<LastName>Feedback</LastName>
</Sender>
<Recipients>
<Recipient>
<Id>c1a5e7a5-7b16-4e34-9479-3e3ee60add35</Id>
<Email>email@domain.com</Email>
<FirstName>Mark</FirstName>
<LastName>Fancy</LastName>
<OriginalSender>email@domain.com</OriginalSender>
<Status>Not Started</Status>
<SentOn>2012-08-29 11:04:26</SentOn>
<LastActivityDate/>
<FinishedOn/>
<IsDismissed>False</IsDismissed>
<IsForwarded>False</IsForwarded>
<LinkToSurvey>http://www.URLHERE.com/v20/surveys/take.aspx?ident=c1a5e7a5-7b16-4e34-9479-3e3ee60add35</LinkToSurvey>
<EmailSubject>Tell Us How We Did</EmailSubject>
<Responses/>
</Recipient>
</Recipients>
<Questions>
<Question>
<Title>Please evaluate how well the services provided met your expectations in the following areas:</Title>
<Category>Expectations</Category>
<IsCustom>False</IsCustom>
<Order>1</Order>
</Question>
<Question>
<Title/>
<Category>Helpfulness</Category>
<IsCustom>False</IsCustom>
<Order>2</Order>
</Question>
<Question>
<Title/>
<Category>Responsiveness</Category>
<IsCustom>False</IsCustom>
<Order>3</Order>
</Question>
<Question>
<Title/>
<Category>Quality</Category>
<IsCustom>False</IsCustom>
<Order>4</Order>
</Question>
<Question>
<Title/>
<Category>Accuracy</Category>
<IsCustom>False</IsCustom>
<Order>5</Order>
</Question>
<Question>
<Title/>
<Category>Schedule</Category>
<IsCustom>False</IsCustom>
<Order>6</Order>
</Question>
<Question>
<Title/>
<Category>Budget</Category>
<IsCustom>False</IsCustom>
<Order>7</Order>
</Question>
<Question>
<Title/>
<Category>Scope and Fees</Category>
<IsCustom>False</IsCustom>
<Order>8</Order>
</Question>
</Questions>
<Tags/>
<SentFromGenericEmail>False</SentFromGenericEmail>
<IncludeNPS>False</IncludeNPS>
<InvitationText>Hello, please help us out!</InvitationText>
<ThankYouMessage>Thank you for your feedback!</ThankYouMessage>
</Survey>
</List>
</Response>

Open in new window



Now here - (and please be gentle folks - not a programmer but I'm trying to learn) - is what I've attempted to code to return the value.  

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class CFTGetSurveys2
     Inherits System.Web.Services.WebService

    Dim Link As String

    <WebMethod()> _
    Public Function HelloWorld(ByVal ProjectNumber As String) As String


        Dim EntireXML As String = "https://localhosthost/api/surveyssent?UserName=feedback@company.com&Password=company&output=xml"
        Dim doc = XDocument.Load(EntireXML)

        Dim query = From cust In doc...<List> _
                    Where cust.<Survey>.<Project>.<Number>.Value = ProjectNumber And cust.<Survey>.<SurveyTemplate>.<Id>.Value = "95" _
                    Select Link = cust.<Survey>.<Recipients>.<Recipient>.<LinkToSurvey>.Value

        Return Link




    End Function



End Class

Open in new window


Am I approaching this remotely close to how I should?  I don't get anything returned from the function except the top of the XML file -
0
Scudboy
Asked:
Scudboy
  • 2
1 Solution
 
käµfm³d 👽Commented:
You are returning the variable Link from your web method, but I don't see where you are assigning anything to it. Should you not be returning the result of the LINQ query?

e.g.

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class CFTGetSurveys2
     Inherits System.Web.Services.WebService

    Dim Link As String

    <WebMethod()> _
    Public Function HelloWorld(ByVal ProjectNumber As String) As String


        Dim EntireXML As String = "https://localhosthost/api/surveyssent?UserName=feedback@company.com&Password=company&output=xml"
        Dim doc = XDocument.Load(EntireXML)

        Dim query = From cust In doc...<List> _
                    Where cust.<Survey>.<Project>.<Number>.Value = ProjectNumber And cust.<Survey>.<SurveyTemplate>.<Id>.Value = "95" _
                    Select Link = cust.<Survey>.<Recipients>.<Recipient>.<LinkToSurvey>.Value

        Return query




    End Function



End Class

Open in new window

0
 
ScudboyAuthor Commented:
I think you're right - so I went ahead and changed this, trying to accmodate for returning a string value but I still think I'm not doing something correctly with the query of the XML nodes.  Here's the modified code:

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class CFTGetSurveys2
     Inherits System.Web.Services.WebService

    Dim Link As String


    <WebMethod()> _
    Public Function HelloWorld(ByVal ProjectNumber As String) As String


        Dim EntireXML As String = "https://www.designfacilitator.com/api/surveyssent?UserName=feedback@fullsailpartners.com&Password=fullsailpartners&output=xml"
        Dim doc = XDocument.Load(EntireXML)

        Dim query = From cust In doc...<Response> _
                    Where cust.<List>.<Survey>.<Project>.<Number>.Value = ProjectNumber _
                    Select Link = cust.<List>.<Survey>.<Recipients>.<Recipient>.<LinkToSurvey>.Value


        Return query.ToString






    End Function



End Class

Open in new window


which returns this value:

<?xml version="1.0" encoding="UTF-8"?>
<string xmlns="http://tempuri.org/">System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String]</string>

Open in new window

after supplying the Project parameter.  I'm wondering if I should not be using Linq at all - keep in mind this is a serious novice trying to fight his way through this, so the decision to utilize the linq querying capabilities may have been a bad one.
0
 
ScudboyAuthor Commented:
No response -
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now