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="t est" myAttribute2="t est2"/>
. . .
</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(f ileName, Encoding.UTF8);
// specify serialization details
tw.Formatting = Formatting.Inde nted;
tw.Indentation = 8;
tw.QuoteChar = '\"';
// No need for a start element
//tw.WriteStartDo cument();
tw.WriteStartEl ement("myRootNo de");
tw.WriteStartEl ement("myChildN ode1");
tw.WriteStartEl ement("myChildN ode2");
tw.WriteAttribu teString("myAtt ribute1", "test");
tw.WriteAttribu teString("myAtt ribute2", "test2");
tw.WriteEndElem ent(); // myChildNode2
tw.WriteEndElem ent(); // myChildNode1
tw.WriteEndElem ent(); // myRootNode
// No need for a start element
//tw.WriteEndDocu ment();
// close the stream
tw.Close();
Thanks for your time and input,
Josh Blair
Evergreen, CO
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="t est" myAttribute2="t est2"/>
. . .
</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(f ileName, Encoding.UTF8);
// specify serialization details
tw.Formatting = Formatting.Inde nted;
tw.Indentation = 8;
tw.QuoteChar = '\"';
// No need for a start element
//tw.WriteStartDo cument();
tw.WriteStartEl ement("myRootNo de");
tw.WriteStartEl ement("myChildN ode1");
tw.WriteStartEl ement("myChildN ode2");
tw.WriteAttribu teString("myAtt ribute1", "test");
tw.WriteAttribu teString("myAtt ribute2", "test2");
tw.WriteEndElem ent(); // myChildNode2
tw.WriteEndElem ent(); // myChildNode1
tw.WriteEndElem ent(); // myRootNode
// No need for a start element
//tw.WriteEndDocu ment();
// close the stream
tw.Close();
Thanks for your time and input,
Josh Blair
Evergreen, CO
Comment