xmlnode as custom object

Greetings,

I have seen this question posted a few times, but the 
answers have not helped me.

I have used the program xsd.exe to generate several c# 
classes from a client provided xsd template.  I now wish 
take a sizeable amount of data and create an xml file 
based on these classes.  My intent is to use xmldocument 
to build up the xml and then stream it to a file.  My 
problem is I cannot use my new classes as nodes since 
they are not derived from nodes and they cannot be cast 
as such.

What would be the best way to approach this?


Cheers, Ian Williamson


0
bmcpeake1 (4)
7/29/2003 12:45:12 AM
dotnet.xml 7266 articles. 0 followers. Follow

5 Replies
472 Views

Similar Articles

[PageSpeed] 19

Use the classes you created, then do the following:

    YourClass c = new ...
    // populate it...
    XmlSerializer s = new XmlSerializer(typeof(YourClass));
    s.Serialize(c, Console.Out);


"Ian Williamson" <bmcpeake@nospam.shaw.ca> wrote in message
news:042e01c3556a$ab7d0f20$a601280a@phx.gbl...
> Greetings,
>
> I have seen this question posted a few times, but the
> answers have not helped me.
>
> I have used the program xsd.exe to generate several c#
> classes from a client provided xsd template.  I now wish
> take a sizeable amount of data and create an xml file
> based on these classes.  My intent is to use xmldocument
> to build up the xml and then stream it to a file.  My
> problem is I cannot use my new classes as nodes since
> they are not derived from nodes and they cannot be cast
> as such.
>
> What would be the best way to approach this?
>
>
> Cheers, Ian Williamson
>
>


0
Chris
7/29/2003 4:54:18 AM
I am at that point now.  What I need to know is how to 
take the serialized object and add it as a fully fleshed 
out node.

If I do it like the code below, the serialized object 
just ends up being a big string with all my properties 
and attributes butted up beside each (ie. not formatted 
XML).  I know this is because I am defining the new node 
as type Element, but I do not see any way to create a 
complex node use CreateNode.

XmlDocument doc = new XmlDocument();
doc.LoadXml("<test></test>");
XmlNode root = (XmlNode)doc.DocumentElement;
XMLExport.Schemas.Transmission tran = new 
XMLExport.Schemas.Transmission();
tran.BatchCount = "10";
StringWriter sw = new StringWriter(new StringBuilder());
XmlSerializer ser = new XmlSerializer(typeof
(XMLExport.Schemas.Transmission));
ser.Serialize(sw, tran);
XmlNode elem = doc.CreateNode
(XmlNodeType.Element, "transmission", sw.ToString());
root.AppendChild(elem);

[System.Serializable]
public class HBSTransmission {
    
    [System.Xml.Serialization.XmlElementAttribute
(DataType="integer")]
    public string BatchCount;
}



>-----Original Message-----
>Use the classes you created, then do the following:
>
>    YourClass c = new ...
>    // populate it...
>    XmlSerializer s = new XmlSerializer(typeof
(YourClass));
>    s.Serialize(c, Console.Out);
>
>
>"Ian Williamson" <bmcpeake@nospam.shaw.ca> wrote in 
message
>news:042e01c3556a$ab7d0f20$a601280a@phx.gbl...
>> Greetings,
>>
>> I have seen this question posted a few times, but the
>> answers have not helped me.
>>
>> I have used the program xsd.exe to generate several c#
>> classes from a client provided xsd template.  I now 
wish
>> take a sizeable amount of data and create an xml file
>> based on these classes.  My intent is to use 
xmldocument
>> to build up the xml and then stream it to a file.  My
>> problem is I cannot use my new classes as nodes since
>> they are not derived from nodes and they cannot be cast
>> as such.
>>
>> What would be the best way to approach this?
>>
>>
>> Cheers, Ian Williamson
>>
>>
>
>
>.
>
0
bmcpeake1 (4)
7/29/2003 5:12:29 PM
Ian,
the key insight here is that using xsd.exe to generate classes, you will be
doing XML Serialization.  This means you will not (typically) be dealing
with XmlDocument, XmlNode, and XmlTextWriter, in your app code, but instead
with domain types (eg, YourClass, which is derived from your XSD).  The XML
representing the content of the instances of those types, is generated for
you by the XmlSerializer.

If you want to go in the reverse direction - starting with XML data and
generating instances of classes from that XMl - you can do that also.  Again
you use the serializer for this, not XmlDocument or XmlTextReader, etc.

"Chris Lovett" <chris@!nospam!.net> wrote in message
news:vibvfksnnql857@corp.supernews.com...
> Use the classes you created, then do the following:
>
>     YourClass c = new ...
>     // populate it...
>     XmlSerializer s = new XmlSerializer(typeof(YourClass));
>     s.Serialize(c, Console.Out);
>
>
> "Ian Williamson" <bmcpeake@nospam.shaw.ca> wrote in message
> news:042e01c3556a$ab7d0f20$a601280a@phx.gbl...
> > Greetings,
> >
> > I have seen this question posted a few times, but the
> > answers have not helped me.
> >
> > I have used the program xsd.exe to generate several c#
> > classes from a client provided xsd template.  I now wish
> > take a sizeable amount of data and create an xml file
> > based on these classes.  My intent is to use xmldocument
> > to build up the xml and then stream it to a file.  My
> > problem is I cannot use my new classes as nodes since
> > they are not derived from nodes and they cannot be cast
> > as such.
> >
> > What would be the best way to approach this?
> >
> >
> > Cheers, Ian Williamson
> >
> >
>
>


0
dinoch (54)
7/29/2003 5:21:12 PM
Looks like my original response got lost in the ether.

I am currently doing what you suggest, I just have no 
idea how to take that serialized string, create a complex 
node from it, and append it to my document.

XmlDocument doc = new XmlDocument();
XmlDeclaration decl = doc.CreateXmlDeclaration
("1.0", "UTF-8", null);
doc.AppendChild(decl);

Root myRoot = new Root();
myRoot.BatchCount = "10";
StringWriter sw = new StringWriter(new StringBuilder());
XmlSerializer ser = new XmlSerializer(typeof(Root));
ser.Serialize(sw, myRoot);
XmlNode elem = doc.CreateNode
(XmlNodeType.Element, "RootNode", "myURI");
elem.InnerText = sw.ToString();
doc.AppendChild(elem);

This of course just adds an unformatted string instead of 
the complex node structure.

[System.Xml.Serialization.XmlRootAttribute
(Namespace="myURI", IsNullable=false)]
public class Root
{
  [System.Xml.Serialization.XmlElementAttribute
(DataType="integer")]
  public string BatchCount;
        
  public string Type;
        
  public string Creator;
}

>-----Original Message-----
>Use the classes you created, then do the following:
>
>    YourClass c = new ...
>    // populate it...
>    XmlSerializer s = new XmlSerializer(typeof
(YourClass));
>    s.Serialize(c, Console.Out);
>
>
>"Ian Williamson" <bmcpeake@nospam.shaw.ca> wrote in 
message
>news:042e01c3556a$ab7d0f20$a601280a@phx.gbl...
>> Greetings,
>>
>> I have seen this question posted a few times, but the
>> answers have not helped me.
>>
>> I have used the program xsd.exe to generate several c#
>> classes from a client provided xsd template.  I now 
wish
>> take a sizeable amount of data and create an xml file
>> based on these classes.  My intent is to use 
xmldocument
>> to build up the xml and then stream it to a file.  My
>> problem is I cannot use my new classes as nodes since
>> they are not derived from nodes and they cannot be cast
>> as such.
>>
>> What would be the best way to approach this?
>>
>>
>> Cheers, Ian Williamson
>>
>>
>
>
>.
>
0
bmcpeake1 (4)
7/29/2003 6:44:20 PM
Try using elem.InnerXml = sw.ToString().  InnerText escapes chars such as <
and >.  InnerXml doesn't do this though.

HTH,
Dan Wahlin

Wahlin Consulting
Microsoft MVP- ASP.NET and XML Web Services
http://www.xmlforasp.net


"Ian Williamson" <bmcpeake@nospam.shaw.ca> wrote in message
news:00e101c35601$6c01d000$a501280a@phx.gbl...
> Looks like my original response got lost in the ether.
>
> I am currently doing what you suggest, I just have no
> idea how to take that serialized string, create a complex
> node from it, and append it to my document.
>
> XmlDocument doc = new XmlDocument();
> XmlDeclaration decl = doc.CreateXmlDeclaration
> ("1.0", "UTF-8", null);
> doc.AppendChild(decl);
>
> Root myRoot = new Root();
> myRoot.BatchCount = "10";
> StringWriter sw = new StringWriter(new StringBuilder());
> XmlSerializer ser = new XmlSerializer(typeof(Root));
> ser.Serialize(sw, myRoot);
> XmlNode elem = doc.CreateNode
> (XmlNodeType.Element, "RootNode", "myURI");
> elem.InnerText = sw.ToString();
> doc.AppendChild(elem);
>
> This of course just adds an unformatted string instead of
> the complex node structure.
>
> [System.Xml.Serialization.XmlRootAttribute
> (Namespace="myURI", IsNullable=false)]
> public class Root
> {
>   [System.Xml.Serialization.XmlElementAttribute
> (DataType="integer")]
>   public string BatchCount;
>
>   public string Type;
>
>   public string Creator;
> }
>
> >-----Original Message-----
> >Use the classes you created, then do the following:
> >
> >    YourClass c = new ...
> >    // populate it...
> >    XmlSerializer s = new XmlSerializer(typeof
> (YourClass));
> >    s.Serialize(c, Console.Out);
> >
> >
> >"Ian Williamson" <bmcpeake@nospam.shaw.ca> wrote in
> message
> >news:042e01c3556a$ab7d0f20$a601280a@phx.gbl...
> >> Greetings,
> >>
> >> I have seen this question posted a few times, but the
> >> answers have not helped me.
> >>
> >> I have used the program xsd.exe to generate several c#
> >> classes from a client provided xsd template.  I now
> wish
> >> take a sizeable amount of data and create an xml file
> >> based on these classes.  My intent is to use
> xmldocument
> >> to build up the xml and then stream it to a file.  My
> >> problem is I cannot use my new classes as nodes since
> >> they are not derived from nodes and they cannot be cast
> >> as such.
> >>
> >> What would be the best way to approach this?
> >>
> >>
> >> Cheers, Ian Williamson
> >>
> >>
> >
> >
> >.
> >


0
wahlin (15)
8/3/2003 4:08:18 AM
Reply:

Similar Artilces:

How to automate deployment of customizations?
Hello, we have several CRM systems. One for development, one for testing and one for productive use. at the moment, we deploy our changes manually to each of the servers. This is very time conusumable and very risky, because the human faktor in creating errors. Now i am searching the whole web for a solution, to automate our deployments. with deployment i mean to automate: 1. create, update, delete entities 2. create, update, delete mappings 3. create, update, delete attribuntes 4. importing and publishing customisations 5. registering workflow assemblies and plugins 6. manipulating fi...

Custom forms to add a Account/Lead data into CRM
Hey All, Due to requirements of the system we are developing,we need to create a screen which will have 2 entities on the same screen as this isnt possible thru normal customization we need to opt for custom aspx forms and MS CRM SDK to add the data. I need to develop a form and usign CRM SDK populate the upper half of the custom form with account info and provide a data entry screen for the lead entity in the lower half (the same form). I have absolutely no idea how to add a lead entity into the CRM Database using SDK Any links/Sites/code snippets you can provide to me will be helfull. Th...

Custom
I will have a column of nine digit numbers. The first six digits are 999999; the last three digits will vary. How do I format the column so I just have to type in the last three digits and the first six will fill with 9s automatically? I tried custom 999999###. That works where the last three digits are 101, for example. However it doesn't work where the last three digits are 007. I get 9999997. It doesn't pick up 00. Thanks, -- Howard Howard This one works for me. Custom 999999000 Enter 007 and return 999999007 Gord Dibben Excel MVP On Thu, 24 Mar 2005 11:45:14 -0800...

Dynamic chart generation: Run time Error '1004: Method 'Cells' of object'_Global' fai
-------------------------------------------------------------------------------- Hello, I am trying to generate a chart with multiple series. The number o series is not fixed and can be any number. I recorded a macro and the modified the code. 'Counter' refers to the number of the series and have referenced it in a worksheet. I am getting the error in the lin that is bold. Thank you for your help. The code is as follows: Dim Counter As Integer Dim i As Integer Sheets("With TC").Select Counter = Cells(38, 13).Value ActiveChart.ChartType = xlLine With Sheets("VP_Wit...

Custom Receipts
How do I get the full page receipt to show invoice instead of receipt at the top. This just changed without notice and I can't get it back. -- R. W. Bouchard Hi, make a backup of the receipt you want to modify first and then open it in notepad. Use the find tool to locate "Transaction.ReceiptTransactionName" and change it to say "Invoice" (keep the quotes around the word Invoice). NOTE: This change will show "Invoice" on that receipt template regardless of the transaction type. KJ "RWBouchard" wrote: > How do I get the full page rece...

Can I hide a project custom field ?
Hi everyone, I created a project custom fields but since it's a formula field I would like to hide it in the Project Information Panel. How can I do this ? A bit like in PWA, the project detail page never shows formula fields. I'm using Project server 2007 Thanks -- Jean-Sébastien Dubois Hi Jean-S�bastien, Sorry, not possible G�rard Ducouret "Jici" <Jici@discussions.microsoft.com> a �crit dans le message de news: 14F7C89E-74C9-42B9-97CB-45DEBB08A620@microsoft.com... > Hi everyone, > > I created a project custom fields b...

How do I make a Custom Datre Format ie 01.01.05 WK1 (WK is Week 1) sorry about previous post
...

XmlNode
When an XmlNode method returns an XmlNode, such as a child, is this generated on-the-fly or is it the actual component of the internal tree structure? If the parent is moved in the tree, will the pointer remain valid? I have looked at as much of the structure as I can using .NET Reflector and I think it will, but I want to be sure. I 'm planning to add XmlNodes to the Tag property of TreeNodes in a TreeView to be able to persist changes back to the document and I would like to know if this will take up any more memory than when they are not linked in this way, or if it is better to...

Customizing canned SSRS reports for GP
Hi, Is it possible to modify the exisiting SSRS reports that are installed with GP through SRSDeployment? Thanks, Michelle Yes, there is. All of the models for the reports are available for download. Look for the Montego reports. Here are the requirements: 1. Any modifications to the source with the intent of reporting against Microsoft Dynamics GP 9.0 will not be supported. 2. The report models contain references to the following account framework. Maximum account length of 60. 10 segments of length 6. Use Fabrikam, Inc. company database with this account framework for consiste...

Customized thrid party screen.
Hi Team, We have modified Project Maintenance Screen by adding customized control for capturing additional information and this modified screen is referenced in solution using visual studio addon tool. Now whenever we click on any of the navigation button under Browse Box GP is displaying message box for either saving or deleting even though if no change is made on screen. For handling this scenario below mentioned code is implemented in .Net void PreviousButtonToolbar_ClickBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e) { ProjectA...

xmlNode.InnerText vs. xmlNode.Value
I've loaded the following xml into an XMLDocument object: <?xml version="1.0" ?> - <Preferences> <Institution>Argh</Institution> <Speaker>Chigier, Ben (1234)</Speaker> <Worktype>Addendum</Worktype> <speakerCode>1234</speakerCode> </Preferences> I then try to retrieve the value of the Institution node as follows: string s = myxmldoc.SelectSingleNode("/Preferences/Institution").Value; However, s is null after the call. But if I change the call to the following, s is what I'd expect: "A...

Can customers connect and see their account/projects status?
I have not used CRM, but I've got all the sales materials, have the CD's that came with the Action Pack and my MSDN Universal, and would like to see if CRM is the right solution for one of my customers. The run a business where sales people have multiple clients, they share information between each other and the managers (sales/managers), but they would like to share project status with their customers - say a customer (company A) has a project with sales team C and manager Y, is there some means to allow customer A to connect and only see their information? Sorry if this is a...

Make it easy to create a customize style or theme set in Word 07
We have used Word since it's first Windows version and routinely use styles and other custom elements to achieve our desired company look and feel. While the new interface in 07 makes it easy to select various MS designed preset styles, it seems to make the process of creating one company customized style that would be reflected in one Normal.dot for all to use maddeningly difficult to achieve. For example, determining how to make a change and save it to the Normal.dot is clear in some places and very difficult to figure out how to do elsewhere. I believe it would help if ...

How to get the XML path of an XmlNode?
How can I get the full XML path (as string) of a specific XmlNode ? -- Thanks Sharon Sharon wrote: > How can I get the full XML path (as string) of a specific XmlNode ? What is "the full XML Path" of a node, do you have any definition for that? Some XML editors can assist you constructing or maybe even generating an XPath expression. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ Lets say I have the following XML file: <?xml version="1.0" encoding="utf.8"?> <System Name = "System"> <Parameters> <T1&...

Customer Returns
When creating an SOP Return from a customer do I need to create a credit memo also or will the return document take care of everything? And if the customer is current and paid by credit card is there a way to credit the customers cc account or do I need to cut a check? Thanks Gi GiJeet, 1. When you create a SOp Return, it'll take care of everything. No need to create a credit memo. Once you post SOp Return, Go to Apply Sales Documents, Select the Return Document, then apply it against your invoice. That's it. 2. For Credit card, You need t first setup the Credit Card Account in ...

Custom Counter
Is there anywhy to have a button that when clicked you get a form with a new record that has a auto number already present. Currently were the auto number would display i get (AutoNumber) I know it will update onces you type but i want to be able to save a blank record that only contains the number. The Records a profiles and sometime it is require to skip some and then come back later to fill in the data. The best way to do this is to not use an autonumber. That field type can be problematic, and if you need sequential numbers, a deleted record number will not be reused. Instead on...

XmlSerialization to XmlNode
I have a schema that I load into classes that mirror the schema using the XmlSerialization. The schema contains an xsd:Any that I load into 'Extra' as follows: [XmlElement(ElementName="Extra")] public XmlNode Extra { get { return extra;} set { extra = value;}} However, if I have: <Something> <Extra> <a>something</a> <b>another thing</b> </Extra> </Something> I would expect Extra to contain an XmlNode of : <Extra> <a>something</a> <b>another thing</b> <...

Customizing Menu (Right Click Menu)
Being on a worksheet on a right click I get a menu: -cut -copy -paste -paste special .... I would like to add some command or macro to this menu, but I don't know how to edit this menu in project view. Could some one give me a piece of advice of how to get there? Tomek Works lovely. There is no better way out than newsgroups. I feel it every day. Thanks Bernie Tomek "Bernie Deitrick" <deitbe@consumer.org> wrote in message news:%23vYfIutRDHA.2892@TK2MSFTNGP10.phx.gbl... > Tomek, > > Use the first macro below to add a button that calls the second macro b...

custom view question
When looking at accounts or contacts there is a drop down to view "Active accounts" or My Active Accounts", etc., how can I get a view of active accounts for each sales rep? ver 4.0 Thanks Brian On Sep 3, 12:17=A0pm, "BrianT" <br...@NOSPAM.com> wrote: > When looking at accounts or contacts there is a drop down to view "Active > accounts" or My Active Accounts", etc., =A0how can I get a view of active > accounts for each sales rep? > > ver 4.0 > > Thanks > Brian Brian, If you just want it for you, you can use Advanc...

Problem with XmlNode.ChildNodes across different machines
I'm having the darndest XML config file problem that I really need help with. I'm supporting a .NET 1.1 desktop application with its own config file, and I implement IConfigurationSectionHandler so I can have a custom config section in my config file. The IConfigurationSectionHandler.Create method just returns the 'section' XmlNode back to the consumer. The config file looks kind of like this: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="MyConfigSettings" type="MyAssembl...

Naming a chart object
When charts are created they are named "chart 1", "chart 2", and so on I need to name a chart in order to update it from vba, but when select the chart I cannot click in the name box? Help -- Message posted from http://www.ExcelForum.com Hi martinu, To rename a chart, hold the shift key down and select the chart. This selects the chart object instead of the chart area. You can then rename as usual. -- Ed Ferrero http://edferrero.m6.net Thanks Ed, so simple when you know how. --- Message posted from http://www.ExcelForum.com/ ...

Using Custom view with business alerts
Hi, Is there any way to create business alert on a custom view i have built in the company database? thanks Hi Alaa, This is currenty not supported. Hope this helps! Cheers, Dennis Araullo, MACS Microsoft Certified Technology Specialist GP,CRM,AX MCITP Installation and Configuration AX 2009 MCITP Database Administrator SQL 2008 Citrix Certified Enterprise Administrator "Alaa Ramadan" wrote: > Hi, > Is there any way to create business alert on a custom view i have built in > the company database? > > thanks > ...

How to custom the scroll bar?
I realized my scroll bar from CWnd, but i found it's difficult to disable the original scroll bars attached the specified window with style WS_VSCROLL or WS_HSCROLL, and the original scroll bars always be shown. But when I try to create the host window without style WS_VSCROLL and WS_HSCROLL, the scroll infomation will be not got properly. thanks! ...

how to transform escaped xml contents in xmlnode
Hi, I have an XML document, created from ADO DataSet, which contains XML data in some nodes shown below: <NewDataSet> <Table> <field_name>My Selection</field_name> <field_type>dropdown</field_type> <field_choice_text> &lt;Choices&gt;&lt;Choice choice_text=\"xxx\" /&gt;&lt;Choice choice_text=\"yyy\" /&gt;&lt;Choice choice_text=\"zzz\" /&gt;&lt;/Choices&gt; </field_choice_text> <field_answer> xxx </field_answer> </Table> </NewDataSet> How can I get ...

Custom Help File
Is anyone aware of a way to add a custom help file to an excel 2002 workbook? I'd like for a user to be able to highlight a specific word and find the word in the custom help file accordingly. Suggestions appreciated! ...