Results 1 to 15 of 15

Thread: If you work with XML...

  1. #1

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464

    If you work with XML...

    If you are working with XML in your application, you need to know about the xsd.exe tool. I just starting to use the tool, and am in love with it. It comes with your VS.Net install, so no files to download.

    I have taken 10 XSD documents, and created classes that I can use programmically. When I am done, I can serialize the classes and bam, I am assured that they match the schema. It is perfect.

    I can see lots of uses for this tool, so I thought I would let others know about it. I knew it was there, just didn't realize the power until that little lightbulb went off in my head yesterday!

    http://msdn.microsoft.com/library/de...ToolXsdexe.asp

  2. #2
    Lively Member TLord's Avatar
    Join Date
    Jun 2004
    Posts
    95
    I want to add a tip for help also: Anybody facing some problems with identifying elements in a normal dataset can use this tool for creating Strongly Typed DataSets.
    Do you think my life is easy?
    Do you think it's good to win?
    do you think it's nice to kill?
    Do you think learning is a must?
    Do you think computers are nothing?
    Do you think this post is stupid?
    Do ypu think we're really humen?

    DO YOU THINK IT'S GOOD TO THINK AT ALL? ? ? ! ! !

  3. #3
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    Im about to start a project where I want to use strongly typed datasets and XML.

    Basically it's a simple asp.net app that will use all the latest stuff we have learned in our company, OO, n-tier, patterns etc. It is a simple maintanence app where you can do CRUD stuff.
    The database is SQL server and is already designed by our db department, and they have mailed me the schema file. It's a simple database with about 12 tables with various joins and keys.

    Now I want to use their design to build my OO model with classes and strongly typed datasets. Somehow I want to make some use of the existing db model and map that to my business logic and db layer.

    Why do I want to use this? Well, if I list all products, then select one product from the list, there is a "save info to file" button. When I click that I want to serialize an xml file based on the info that is present in the UI... without any boring manual coding... the info should already be available to me in the typed dataset which the datagrid is bound to...

    As I understand it I have two choices when it comes to designing the business logic, either write custom classes(like we have done before) and make them serializable, OR make typed datasets instead.


    All I need are some good advice and a few pointers, and then I can take it from there...

    ps I really want to show off how we can benefit from xml and typed datasets and how the db department and the programmers can work more closely together... ds

    Kind regards
    Henrik

  4. #4
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769
    I have toiled with the same question for ages now.
    either write custom classes
    or
    make typed datasets
    .

    The conclusion I have come to is:
    If the classes are doing more than just CRUD (i.e. complex calculations, relationship management and object manipulation), and the system demands better interaction (e.g. enterprise event messaging), then I use a custom class. Otherwise I use datasets.

    With the functionality built into datasets, you can get away with just using datasets. However, I think it is important to make them typed using an xsd, and as a programmer/architect/engineer, ALWAYS treet them as if they were your custom class. In your mind, you should see that typed dataset as your custom class. I have seen designs go to s**t when developers loose sight of their objects. Anyway, thats just the way I like to think of it to keep my mind clear about what is what.

    So, back to your problem,
    I think you can just use a typed dataset for your CRUD operations and serialize them using an xml formatter.

    Please can you inform us of the route you decided to follow, and of course, a success rating... It would be interesting to hear what others thought of this problem, and i'm sure, there are plenty of people who have been there.

  5. #5
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769
    Here is another helpful commandline tool downloadable from Microsoft website:
    msxsl.exe

    You can do xml transformations from the commandline using this tool. I have found it very helpful!

    Of course, you can write your own in a couple of minutes, but why reinvent the wheel?

  6. #6
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    The problem Im facing is that if I have 40 methods in my DAL, 35 of them are special operations with HUGE sql querys performing 3-4 joins... how can I use typed datasets with them? Of course if you read only one table, then it is easy to perform cruds using the dataadapter.. but what if you need to update 6 tables at a time, just because you fetched data from 6 tables to get the correct relationships???? Then I use custom classes and custom DAL methods... because often in the projects I worked wit the data model is so complex and relations are all over the place. The concepts are so very abstract it is hard to understand it using typed datasets...

    I think the customer->person->salespoint->item etc etc only exist in the textbook.. such simple applications cannot be found in real life. I have tried... Just as an example, what if you want to update a field from this select query:

    VB Code:
    1. ELECT     dbo.gq64_order_head.internal_order_no, dbo.gq64_order_head.part_no, dbo.gq64_order_head.denomination_swe,
    2.                       CASE WHEN dbo.gq56_work_center.work_center_denom_gps IS NULL
    3.                       THEN dbo.gq65_order_operation.work_center ELSE dbo.gq56_work_center.work_center_denom_gps END AS work_center,
    4.                       dbo.gq65_order_operation.part_no_core, dbo.gq53_core.prel_denomination,
    5.                       CASE WHEN dbo.gq65_order_operation.operation_prio < 999 THEN dbo.gq65_order_operation.operation_prio ELSE dbo.gq64_order_head.planned_prio
    6.                        END AS prio
    7. FROM         dbo.gq65_order_operation INNER JOIN
    8.                       dbo.gq64_order_head ON dbo.gq65_order_operation.part_no = dbo.gq64_order_head.part_no AND
    9.                       dbo.gq65_order_operation.internal_order_no = dbo.gq64_order_head.internal_order_no INNER JOIN
    10.                       dbo.gq56_work_center ON dbo.gq65_order_operation.work_center = dbo.gq56_work_center.work_center INNER JOIN
    11.                       dbo.gq53_core ON dbo.gq65_order_operation.part_no_core = dbo.gq53_core.part_no_core
    12. WHERE     (dbo.gq65_order_operation.operation_no = @OpNo) AND (dbo.gq64_order_head.internal_order_no = @OrderNo) AND
    13.                       (dbo.gq64_order_head.part_no = @PartNo)


    as you can see this is a normal sql query I work with... and how do you apply this into a datatable.. and an even more important question, how does the dataadapter generate updates, inserts and deletes???? that is the functionality I want!!!

    kind regards
    henrik

  7. #7
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769
    Firstly, place this in a new thread! You will get more answers that way.

  8. #8
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769

  9. #9
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: If you work with XML...

    Hi shunt:

    Sory return to your post,but i need some help here with schemas...
    I have a Schema.xsl that I want to convert to a .xml file...
    In this moment I have the reference in my code:

    Code:
    Imports System.Xml
    Imports System.Xml.Schema
    Can you post some code to exemplified the way to do this?

    Thanks

  10. #10
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769

    Re: If you work with XML...

    Hi, I don't think I fully understand your requirement. An XML Schema is XML. You can load a schema file directly into an XMLDocument object. Also, if you have an .XSL file you can simply rename the file to .XML.

    Open the xsl file with IE or notepad and you will see that it is an XML file.

    Perhaps you actually want to generate an XML file from an XSL file?

  11. #11
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: If you work with XML...

    Hi:

    Perhaps you actually want to generate an XML file from an XSL file?
    Yes that's it...but I don't know the way to do this programatically...I need some help with a few lines of code if you have ok?

    Thanks

  12. #12
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769

    Re: If you work with XML...

    Sorry. Firstly I made a mistake. A schema file has a file extension ".xsd". A template file has a file extension ".xsl".

    An XSD (schema) describes the layout of an XML file. An XSL (template) transforms one xml file from one format to another.

    I see you said "Schema.xsl", so for clarrity, do you have a schema or a template?

  13. #13
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: If you work with XML...

    Sory...I Have a .XSD(schema) file

  14. #14
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Three Anchor Bay, Cape Town, South Africa
    Posts
    769

    Re: If you work with XML...

    Okay... A schema file simply defines what the XML must conform to. Unfortunately, there is no magic "generate" function that will generate all the nodes required by your XSD. The good news is that an XSD is essentially the same as the dictionary of a database. It describes a set of tables and a set of attributes. I have never tried to use an XSD to generate XML before, but if I was to try, I would start by using an ADO.NET dataset object. Create a dataset object and then try using the ReadXMLSchema function. This should initialize the table objects in the dataset and you can then populate tables using standard ADO.NET methods. Then when you want to generate the XML just use WriteXml or GetXml functions.
    Just google "dataset ReadXmlSchema" for examples

  15. #15
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: If you work with XML...

    ok...I will try your suggestion

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width