473,226 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

How to parse received xml into variables

I'm using the following code to receive information from a web service:

Dim o As New MyWebServiceProxyClient.DataImport
Dim r As New MyWebServiceProxyClient.DataImportCompanyResult

r = o.DataImportCompany("login1", "login2", "pwd", "lang", "package",
"searchno")

r contains FieldNames and FieldValues. How can I loop through r and put
the FieldNames and FieldValues into variables?

Regards,

S

May 10 '06 #1
3 1235
If r is xml you can load the xml into an xml reader, then use the reader to
go to each element, get the value from the element and assign it into a
variable.

"st****@gmail.com" wrote:
I'm using the following code to receive information from a web service:

Dim o As New MyWebServiceProxyClient.DataImport
Dim r As New MyWebServiceProxyClient.DataImportCompanyResult

r = o.DataImportCompany("login1", "login2", "pwd", "lang", "package",
"searchno")

r contains FieldNames and FieldValues. How can I loop through r and put
the FieldNames and FieldValues into variables?

Regards,

S

May 10 '06 #2
Thank's! Can you provide some more details how to do this?

Regards,

S

May 10 '06 #3
The 2 code snippets below show how to create an xml reader in the web method.
The second snippet shows how to use a static method named NewFromXml on a
Data Transfer Object. The newFromXml method uses the reader to poupulate
itself.

Snippet 1, parse the incomming data:
[WebMethod(Description="Creates a training entry and its associated
child records." +
"Consumers of this method should invoke this method using a
predifined info path form." +
"The value passed in should be an xml document. The xml document
will be transformed " +
"into a DTO then into an Entity and then persisted to the database.")]
public int CreateTrainingEntry(string value)
{
Debug.WriteLine(value);

StringReader inputStream = new StringReader(value);
XmlTextReader textReader = new XmlTextReader(inputStream);

XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreComments = true;
settings.IgnoreWhitespace = true;
settings.CloseInput = true;
XmlReader reader = XmlReader.Create(textReader, settings);

TrainingEntry tmpEntry = null;
while (reader.Read())
{
if (reader.IsStartElement("newTrainingEntry",
Constants.DEFAULT_NAMESPACE))
{
tmpEntry = TrainingEntry.NewFromXml(reader.ReadOuterXml());
}
}

int newId = -1;
if (tmpEntry != null)
{
AdminManager manager = new AdminManager();
manager.CreateTrainingEntry(tmpEntry,out newId);
}

return newId;
}
Snippet 2, demonstrates the NewFromXml method.....
/// <summary>
/// Creates a new TrainingEntry DTO using the xml string that is
passed
/// to this method.
/// </summary>
/// <param name="outerXml">Xml to be used when creating the
DTO</param>
/// <returns>Instance of the TrainingEntry DTO</returns>
public static TrainingEntry NewFromXml(string outerXml)
{
TrainingEntry entry = new TrainingEntry();

XmlReader reader = NewReader(outerXml);

while (reader.Read())
{
if (reader.IsStartElement("TrainingDate",
Constants.DEFAULT_NAMESPACE))
entry.TrainingDate = reader.ReadElementContentAsDateTime(
"TrainingDate", Constants.DEFAULT_NAMESPACE);

if (reader.IsStartElement("TrainingNote",
Constants.DEFAULT_NAMESPACE))
entry.TrainingNote = reader.ReadElementContentAsString();

if (reader.IsStartElement("StartTime",
Constants.DEFAULT_NAMESPACE))
entry.StartTime = reader.ReadElementContentAsString();

if (reader.IsStartElement("EndTime",
Constants.DEFAULT_NAMESPACE))
entry.EndTime = reader.ReadElementContentAsString();

if (reader.IsStartElement("WeightTrainingDetails",
Constants.DEFAULT_NAMESPACE))
{
entry.WeightTrainingDetails =
WeightTrainingExerciseDetail.NewFromXml(reader.Rea dOuterXml());
}

if (reader.IsStartElement("CardioTrainingDetail",
Constants.DEFAULT_NAMESPACE))
{

CardioTrainingExerciseDetail.AddFromXml(reader.Rea dOuterXml(),
entry.CardioTrainingDetail);
}
}
return entry;

}
Lastly, this is what the incomming XML looks like:
<tns:NewTrainingEntry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tns="http://tempuri.org/"
xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns1="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-04-13T04:12:38"
xmlns:ns2="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-04-13T04:24:03"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-04-13T03:32:17" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003">
<tns:newTrainingEntry>
<tns:TrainingDate>2006-04-12T00:00:00</tns:TrainingDate>
<tns:TrainingNote>test</tns:TrainingNote>
<tns:StartTime>11:30</tns:StartTime>
<tns:EndTime>12:30</tns:EndTime>
<tns:WeightTrainingDetails>
<tns:Sets>
<tns:Set>
<tns:Weight>10</tns:Weight>
<tns:Reps>12</tns:Reps>
</tns:Set>
<tns:Set>
<tns:Weight>11</tns:Weight>
<tns:Reps>12</tns:Reps>
</tns:Set>
<tns:Set>
<tns:Weight>12</tns:Weight>
<tns:Reps>12</tns:Reps>
</tns:Set>
<tns:Set>
<tns:Weight>20</tns:Weight>
<tns:Reps>10</tns:Reps>
</tns:Set>
</tns:Sets>
<tns:ExerciseId>2</tns:ExerciseId>
<tns:ExerciseNote>test</tns:ExerciseNote>
</tns:WeightTrainingDetails>
<tns:CardioTrainingDetail>
<tns:CardioTrainingExerciseDetail>
<tns:ExerciseId>10</tns:ExerciseId>
<tns:Duration>
<tns:Seconds>0</tns:Seconds>
<tns:Hours>0</tns:Hours>
<tns:Minuites>25</tns:Minuites>
<tns:Days>0</tns:Days>
</tns:Duration>
<tns:Distance>1.00</tns:Distance>
<tns:Calories>200</tns:Calories>
<tns:TargetHeartRate>150</tns:TargetHeartRate>
<tns:AverageHeartRate>130</tns:AverageHeartRate>
<tns:TimeInTargetZone>
<tns:Seconds>0</tns:Seconds>
<tns:Hours>0</tns:Hours>
<tns:Minuites>25</tns:Minuites>
<tns:Days>0</tns:Days>
</tns:TimeInTargetZone>
</tns:CardioTrainingExerciseDetail>
</tns:CardioTrainingDetail>
</tns:newTrainingEntry>
</tns:NewTrainingEntry>

"st****@gmail.com" wrote:
Thank's! Can you provide some more details how to do this?

Regards,

S

May 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John A. Irwin | last post by:
I'm very new to PHP and am trying to figure out how to parse out a variable "HTTP_REFERER". My reason for this is my site was recently "FEATURED" (sic) on a website called FARK.COM. Because of...
6
by: nate | last post by:
Hello, Does anyone know where I can find an ASP server side script written in JavaScript to parse text fields from a form method='POST' using enctype='multipart/form-data'? I'd also like it to...
2
by: Andrew Ayers | last post by:
All, I am having a problem with an INSERT onto a table I have created. First off, here is the table: --- CREATE TABLE reg ("customer number" SERIAL PRIMARY KEY, "company name" ...
5
by: John Hanley | last post by:
I just received a "parse error at end of input" when compiling my code, but am unsure why. It lists the line as the very last line of my .c file "}"My code compiled fine yesterday, and I only made...
0
by: Klaus Bonadt | last post by:
I would like to parse an email, which I receive from a pop3 account. While the subject and the sender's email address are probably easy to determine, the body seems to be more difficult because of...
6
by: Ian Davies | last post by:
Hello I have found the following script php/java for dynamic menu lists. Where a selection from the first updates (filters items in) the other. I have modified it for my tables. However I am...
1
by: Pupkin | last post by:
Hi, I was excited to use Microsoft Index Server, built into IIS, to set-up a site-search function, but it doesn't, by default, parse the ASP code of the pages it indexes. This makes it sort of a...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
4
by: ShutterMan | last post by:
I have a JSON object as below (data is from SQL Server Northwind Database). But doing an eval on it returns an error "unterminated string constant" or such. Can someone help me pinpoint the...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.