473,805 Members | 2,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting mysql query result to xml

Hi all, I'm a newbie in .net xml programming, so please be patient. And
sorry for my uncorrect english, too.
I'm going to explain my problem:

I've built a web service which responds to ferries timetable requests.
It receives an xml document with this format:
<TimeTableReque st>
<Routes>
<Route>
<Company></Company>
<DeparturePort> ptf</DeparturePort>
<ArrivalPort>pi o</ArrivalPort>
<Date>2006-12-20T13:00:00</Date>
</Route>
<Route>
<Company></Company>
<DeparturePort> pio</DeparturePort>
<ArrivalPort>pt f</ArrivalPort>
<Date>2006-12-23T15:00:00</Date>
</Route>
</Routes>
</TimeTableReques t>

I deserialize the xml file to a TimeTableReques t object through xml
methods provided by C# 2005. Then I query the mysql (rel.5) database
with those parameters and I'd need back an XML file with this format:

<TimeTableRespo nse>
<Solutions>
<Solution>
<Company>trm</Company>
<DeparturePort> ptf</DeparturePort>
<ArrivalPort>pi o</ArrivalPort>
<DepartureDate> 2006-12-23T05:10:00+01: 00</DepartureDate>
<ArrivalDate>20 06-12-23T06:10:00+01: 00</ArrivalDate>
<FareRule>Bas sa Stagione</FareRule>
</Solution>
<Solution>
<Company>trm</Company>
<DeparturePort> ptf</DeparturePort>
<ArrivalPort>pi o</ArrivalPort>
<DepartureDate> 2006-12-22T05:10:00+01: 00</DepartureDate>
<ArrivalDate>20 06-12-22T06:10:00+01: 00</ArrivalDate>
<FareRule>Bas sa Stagione</FareRule>
</Solution>
</Solutions>
</TimeTableRespon se>

Querying the db, I obtain a dataset, and then the xml from it, through
the method GetXml(), but this method gave me an object like this:

<TimeTableRespo nse>
<Solution>
<Company>trm</Company>
<DeparturePort> ptf</DeparturePort>
<ArrivalPort>pi o</ArrivalPort>
<DepartureDate> 2006-12-23T05:10:00+01: 00</DepartureDate>
<ArrivalDate>20 06-12-23T06:10:00+01: 00</ArrivalDate>
<FareRule>Bas sa Stagione</FareRule>
</Solution>
...
</TimeTableRespon se>

i.e. without the "Solutions" (plural) tag. I got this xml loading the
schema file (.xsd) in the dataset, but keeps ignoring that tag. How can
obtain an exact mapping to the schema?
Thanks in advance.

Nov 27 '06 #1
2 3223

create an xmlWriter
use the response dataset's createreader function to create a datareader
of the set
use the writer's writeStartEleme nt method with "Solutions" as the
argument
use the writer's writeStartEleme nt method with "Solution" as the
argument
now use the writer's writeElementStr ing("Company" with
reader.item("Co mpany"))
now use the writer's writeElementStr ing("DepartureP ort" with
reader.item("De parturePort"))

and so on

Then Finish with the writer's writeEndElement ()... twice (one for
Solution, and another for Solutions)

you can clean this up, make a function out of it that returns a stream,
an xmlDocument, Uri to a new file,a new dataSet or dataTable, raw
XML... whatever.

Since the writer is forward only and the datareader you use is a direct
push of the data, performance should be excelent. Its probably the
easiest way to do it, but you must set it up correctly, preferably as a
private or protected function or sub of a class in your Data layer.

On Nov 27, 9:09 am, carlo.gherardu. ..@gmail.com wrote:
Hi all, I'm a newbie in .net xml programming, so please be patient. And
sorry for my uncorrect english, too.
I'm going to explain my problem:

I've built a web service which responds to ferries timetable requests.
It receives an xml document with this format:
<TimeTableReque st>
<Routes>
<Route>
<Company></Company>
<DeparturePort> ptf</DeparturePort>
<ArrivalPort>pi o</ArrivalPort>
<Date>2006-12-20T13:00:00</Date>
</Route>
<Route>
<Company></Company>
<DeparturePort> pio</DeparturePort>
<ArrivalPort>pt f</ArrivalPort>
<Date>2006-12-23T15:00:00</Date>
</Route>
</Routes>
</TimeTableReques t>

I deserialize the xml file to a TimeTableReques t object through xml
methods provided by C# 2005. Then I query the mysql (rel.5) database
with those parameters and I'd need back an XML file with this format:

<TimeTableRespo nse>
<Solutions>
<Solution>
<Company>trm</Company>
<DeparturePort> ptf</DeparturePort>
<ArrivalPort>pi o</ArrivalPort>
<DepartureDate> 2006-12-23T05:10:00+01: 00</DepartureDate>
<ArrivalDate>20 06-12-23T06:10:00+01: 00</ArrivalDate>
<FareRule>Bas sa Stagione</FareRule>
</Solution>
<Solution>
<Company>trm</Company>
<DeparturePort> ptf</DeparturePort>
<ArrivalPort>pi o</ArrivalPort>
<DepartureDate> 2006-12-22T05:10:00+01: 00</DepartureDate>
<ArrivalDate>20 06-12-22T06:10:00+01: 00</ArrivalDate>
<FareRule>Bas sa Stagione</FareRule>
</Solution>
</Solutions>
</TimeTableRespon se>

Querying the db, I obtain a dataset, and then the xml from it, through
the method GetXml(), but this method gave me an object like this:

<TimeTableRespo nse>
<Solution>
<Company>trm</Company>
<DeparturePort> ptf</DeparturePort>
<ArrivalPort>pi o</ArrivalPort>
<DepartureDate> 2006-12-23T05:10:00+01: 00</DepartureDate>
<ArrivalDate>20 06-12-23T06:10:00+01: 00</ArrivalDate>
<FareRule>Bas sa Stagione</FareRule>
</Solution>
...
</TimeTableRespon se>

i.e. without the "Solutions" (plural) tag. I got this xml loading the
schema file (.xsd) in the dataset, but keeps ignoring that tag. How can
obtain an exact mapping to the schema?
Thanks in advance.
Nov 28 '06 #2
Thank you, I'll try with that.

de*******@gmail .com ha scritto:
create an xmlWriter
use the response dataset's createreader function to create a datareader
of the set
use the writer's writeStartEleme nt method with "Solutions" as the
argument
use the writer's writeStartEleme nt method with "Solution" as the
argument
now use the writer's writeElementStr ing("Company" with
reader.item("Co mpany"))
now use the writer's writeElementStr ing("DepartureP ort" with
reader.item("De parturePort"))

and so on

Then Finish with the writer's writeEndElement ()... twice (one for
Solution, and another for Solutions)

you can clean this up, make a function out of it that returns a stream,
an xmlDocument, Uri to a new file,a new dataSet or dataTable, raw
XML... whatever.

Since the writer is forward only and the datareader you use is a direct
push of the data, performance should be excelent. Its probably the
easiest way to do it, but you must set it up correctly, preferably as a
private or protected function or sub of a class in your Data layer.

On Nov 27, 9:09 am, carlo.gherardu. ..@gmail.com wrote:
Hi all, I'm a newbie in .net xml programming, so please be patient. And
sorry for my uncorrect english, too.
I'm going to explain my problem:

I've built a web service which responds to ferries timetable requests.
It receives an xml document with this format:
<TimeTableReque st>
<Routes>
<Route>
<Company></Company>
<DeparturePort> ptf</DeparturePort>
<ArrivalPort>pi o</ArrivalPort>
<Date>2006-12-20T13:00:00</Date>
</Route>
<Route>
<Company></Company>
<DeparturePort> pio</DeparturePort>
<ArrivalPort>pt f</ArrivalPort>
<Date>2006-12-23T15:00:00</Date>
</Route>
</Routes>
</TimeTableReques t>

I deserialize the xml file to a TimeTableReques t object through xml
methods provided by C# 2005. Then I query the mysql (rel.5) database
with those parameters and I'd need back an XML file with this format:

<TimeTableRespo nse>
<Solutions>
<Solution>
<Company>trm</Company>
<DeparturePort> ptf</DeparturePort>
<ArrivalPort>pi o</ArrivalPort>
<DepartureDate> 2006-12-23T05:10:00+01: 00</DepartureDate>
<ArrivalDate>20 06-12-23T06:10:00+01: 00</ArrivalDate>
<FareRule>Bas sa Stagione</FareRule>
</Solution>
<Solution>
<Company>trm</Company>
<DeparturePort> ptf</DeparturePort>
<ArrivalPort>pi o</ArrivalPort>
<DepartureDate> 2006-12-22T05:10:00+01: 00</DepartureDate>
<ArrivalDate>20 06-12-22T06:10:00+01: 00</ArrivalDate>
<FareRule>Bas sa Stagione</FareRule>
</Solution>
</Solutions>
</TimeTableRespon se>

Querying the db, I obtain a dataset, and then the xml from it, through
the method GetXml(), but this method gave me an object like this:

<TimeTableRespo nse>
<Solution>
<Company>trm</Company>
<DeparturePort> ptf</DeparturePort>
<ArrivalPort>pi o</ArrivalPort>
<DepartureDate> 2006-12-23T05:10:00+01: 00</DepartureDate>
<ArrivalDate>20 06-12-23T06:10:00+01: 00</ArrivalDate>
<FareRule>Bas sa Stagione</FareRule>
</Solution>
...
</TimeTableRespon se>

i.e. without the "Solutions" (plural) tag. I got this xml loading the
schema file (.xsd) in the dataset, but keeps ignoring that tag. How can
obtain an exact mapping to the schema?
Thanks in advance.
Nov 29 '06 #3

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

Similar topics

11
15198
by: Bruce A. Julseth | last post by:
Newbie Question: Is there a way to import MS Access into MySQL? Maybe create a CSV or something. If so, what would be the SQL to do this? Thanks... Bruce
2
6585
by: mike m | last post by:
all, was able to piece together the following php/html code. Basically I want to push an SQL query and format it, present it to an html document. The problem appears with the SQL query. When I execute the query from Mysql, it translates the date/time perfectly along with the text msg - however when I call this from php script below, it doesn't produce a date, just the msg text:
2
4026
by: Phil Powell | last post by:
Relevancy scores are normally defined by a MySQL query on a table that has a fulltext index. The rules for relevancy scoring will exclude certain words due to their being too short (minimum default is 4 letters). This is the Fed. Everything is a TLA (three-letter acronym). Therefore, since I'm building a PORTABLE web application, changing MySQL's default settings for fulltext index querying is completely undoable and unrealistic, so...
0
5773
by: Phil Powell | last post by:
The table already has a fulltext index and from there I can use the MySQL fulltext search query to get results as well as the relevancy score. The problem I have is that MySQL has a default setting whereby the minimum amount of characters is 4 for a search. Being that we're government and full of TLA (three-letter acronyms), that is not practical, and furthermore, the app I'm building must be fully portable, so having MySQL tweaked...
4
9342
by: Mark Wilson CPU | last post by:
A colleague has written a prototype program in PHP, using a MySQL database. It's a relatively simple app, with a restricted set of mysql commands used (see below). The MySQL DB is being replaced with an Oracle DB (same schema). My plan 1) globally replace the few mysql commands with intermediate equivalents (such as myDB_connect for mysql_connect) 2) those central functions would then (for now) call the original mysql function to prove...
1
2832
by: Good Man | last post by:
Hi there I've noticed some very weird things happening with my current MySQL setup on my XP Laptop, a development machine. For a while, I have been trying to get the MySQL cache to work. Despite entering the required lines to "my.ini" (the new my.cnf) through notepad AND MySQL Administrator, the cache does not work. So, today I took a peek at the 'Health' tab in MySQL Administrator.
3
2169
by: dean.elwood | last post by:
Hi guys, My first post here and I'm a pascal coder doing his best to move to C/C++ so please go easy on me ;) I'm using the MySQL C API to pull some values from a DB. One of the fields is a float value, but I can't seem to cast this field to a float variable correctly:- if(mysql_exec_sql(&mysql,query)==0) /*success*/
15
2692
by: harvey | last post by:
How do I make PHP create a database for mysql please? I can see how to make tables and I have read all the documents I can find but I don't understand how to make the database itself. All the tutorials I can find seem to bypass the issue by ignoring it? Am I missunderstanding something?
221
367775
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application needs to store entire files, the preferred method is to save the file onto the server’s file-system, and store the physical location of the file in your database. This is generally considered to be the easiest and fastest way to store files. ...
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10356
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10103
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6874
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3839
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.