473,387 Members | 1,693 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,387 software developers and data experts.

Code Generator that writes code to generate an XML doc structure?

Hello,

Has anyone ever seen or created such a code generator?

I'm looking for a sample of a code generator that will generate code
(preferably one that uses C# and the XMLTextWriter) to create an XML
document structure based on an XML file as input.

I have to build some classes that allow me to generate some very
complex/large/nasty XML documents for use in B2B exchange of data (like
invoices, orders, etc.). A third party has dictated the structure and
provided example XML documents. Instead of hand coding these classes,
I'd like to be able to automatically generate them by using these
example XML documents as input. This seems like a fairly easy task but
I haven't run across a demonstration of this yet.

This code generator would walk the elements/nodes, checking for
attributes and other child nodes and output the code necessary to
generate the same XML document structure. See below for an example:

An Example XML file (contents):
===============================

<myRootNode>
<myChildNode1>
<myChildNode2 myAttribute1="test" myAttribute2="test2"/>
. . .
</myChildNode1>
.. . .
</myRootNode>

Example output from the code generator that takes the path of the xml
file above (this is merely a simple example):
==================================================

// instantiate XmlTextWriter over file stream using UTF-8
XmlTextWriter tw = new XmlTextWriter(fileName, Encoding.UTF8);

// specify serialization details
tw.Formatting = Formatting.Indented;
tw.Indentation = 8;
tw.QuoteChar = '\"';

// No need for a start element
//tw.WriteStartDocument();

tw.WriteStartElement("myRootNode");

tw.WriteStartElement("myChildNode1");

tw.WriteStartElement("myChildNode2");

tw.WriteAttributeString("myAttribute1", "test");
tw.WriteAttributeString("myAttribute2", "test2");

tw.WriteEndElement(); // myChildNode2

tw.WriteEndElement(); // myChildNode1

tw.WriteEndElement(); // myRootNode

// No need for a start element
//tw.WriteEndDocument();

// close the stream
tw.Close();

Thanks for your time and input,

Josh Blair
Evergreen, CO

May 25 '06 #1
3 2038
This would be easier to do if you have a corresponding schema document
for each xml file. You can then combine XmlSerializer or XmlTextWriter
to generate the Xml documents based on the schema.

May 25 '06 #2
Dhanvanth,

Thanks for the reply. I was given the formats by a third party and
these documents are in a proprietary xml structure without a schema or
DTD. These XML document structures represent business entities like
invoices, orders, ASNs, etc. Knowing this, would you recommend that I
create a schema for these documents? They are very large and complex
and I currently don't speak XSL/XSD/XSLT, etc. I'd be willing to work
on implementing these techniques if this is the best way. Please let
me know your thoughts.

Josh Blair
Evergreen, CO

May 25 '06 #3
Creating Schema files have their advantages in that we can always be
sure that the format is correct(produce valid XML). But they involve a
lot of time in design.

If each document is huge then producing them manually will take a lot
of code and hard to maintain. Any change in the structure will
typically render all your previous code worthless.

Schemas will help in creating valid objects out of them and you can
easily create valid Xml using a schema file. Also there are tools now
available that will generate schema files from XML documents. You could
try one such at http://www.hitsw.com/xml_utilites/. Remember that they
are only as good as how well the input sample represents your document
structure.

On the other hand, hard coding the production of XML will solve the
problem and be a pretty decent solution if the input formats are pretty
constant and do not change( I have never seen that happen though :-) ).
Also they can be coded fairly easily.

I am not sure of your exact requirements. So I cant advice as to what
to choose. Hope I was of some help

-Dhanvanth
joshblair wrote:
Dhanvanth,

Thanks for the reply. I was given the formats by a third party and
these documents are in a proprietary xml structure without a schema or
DTD. These XML document structures represent business entities like
invoices, orders, ASNs, etc. Knowing this, would you recommend that I
create a schema for these documents? They are very large and complex
and I currently don't speak XSL/XSD/XSLT, etc. I'd be willing to work
on implementing these techniques if this is the best way. Please let
me know your thoughts.

Josh Blair
Evergreen, CO


May 26 '06 #4

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

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
16
by: Tran Tuan Anh | last post by:
Dear all: I need your advice on this matter. I am working on a program which takes some pieces of System-C code in and generate some other System-C code. (System-C code is just C++ with some...
2
by: Marek | last post by:
Actually, the very first question I should ask is "does it make sense at all?". For 2 days I've been trying to generate C# classes using XML schema and xsd.exe tool. So far the results are not...
11
by: Lues | last post by:
Hi, I'm trying to protect some data in tables with encription (you know why, don't you ;)) I must confess that I'm not very expirienced in writing code, especially encription code. Can any...
8
by: Thomas Stegen | last post by:
I have written a code generator. To be more specific it is a code generator generator. As in a generator that generates code generators. If you run the generator on its own source code you get a...
9
by: Hayato Iriumi | last post by:
Hello, I hear some hypes about creating code to generate C# or VB .NET code, that is, code generation (sounds straight forward enough). I haven't really seen how it's done in real world. I'm...
1
by: Marek | last post by:
Actually, the very first question I should ask is "does it make sense at all?". For 2 days I've been trying to generate C# classes using XML schema and xsd.exe tool. So far the results are not...
5
by: Peteroid | last post by:
I know how to use rand() to generate random POSITIVE-INTEGER numbers. But, I'd like to generate a random DOUBLE number in the range of 0.0 to 1.0 with resolution of a double (i.e., every possible...
7
by: js | last post by:
Hi, I'm looking for RSS/ATOM generator I can use in Python. I searched on pypi and the other places but I couldn't find any options on this. (I found many parsers, though) Is there any de-fact...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.