Click to See Complete Forum and Search --> : XML serialization problems
richiebabes
October 16th, 2008, 10:47 AM
I used xsd.exe to create a class. OK, great. So I insert values into each element and now I have an instance of the class full of stuff. But I want to wrap the XML in a header. So I do this:
inputXMLDoc.AppendChild(inputXMLDoc.CreateXmlDeclaration("1.0", null, null));
inputXMLDoc.AppendChild(inputXMLDoc.CreateProcessingInstruction("qbxml", "version=\"CA2.0\""));
XmlElement qbXML = inputXMLDoc.CreateElement("QBXML");
inputXMLDoc.AppendChild(qbXML);
XmlElement qbXMLMsgsRq = inputXMLDoc.CreateElement("QBXMLMsgsRq");
qbXML.AppendChild(qbXMLMsgsRq);
qbXMLMsgsRq.SetAttribute("onError", "stopOnError");
How do I then add the stuff from the XML class to this?
richiebabes
October 16th, 2008, 01:24 PM
Anyone? Is my question not clear?
Arjay
October 16th, 2008, 01:29 PM
It really isn't clear. Are you saying that you are serializing a class instance using XmlSerializer.Serialize and wrap that xml output with the xml you've posted? Btw, please use code tags.
Can you post the xml you would like to end up with?
richiebabes
October 16th, 2008, 01:46 PM
I am not sure what I am doing :blush: since I am new to this world. I have this, for instance, as a class:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class InvoiceAdd
{
private CustomerRef customerRefField;
private ClassRef classRefField;
private ARAccountRef aRAccountRefField;
[...]
And I have the above code for creating a wrapper around the XML - you know, the nasty stuff at the top and bottom.
And I want to put the lot together, i.e. put the above class stuff inside the other stuff to end up with:
<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="7.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnErrror">
<InvoiceAddRq>
<InvoiceAdd defMacro="MACROTYPE">
<CustomerRef>
<ListID >IDTYPE</ListID>
<FullName >STRTYPE</FullName>
[...]
</InvoiceRet>
</InvoiceAddRs>
</QBXMLMsgsRq>
</QBXML>
I am not sure what I am doing :p . If I create an instance of that class how do I actually get it and put it together with the header stuff and then blast it down the web service pipes?
Arjay
October 16th, 2008, 03:24 PM
If I create an instance of that class how do I actually get it and put it together with the header stuff and then blast it down the web service pipes?What webservices are you using? 2.0? WCF services?
richiebabes
October 16th, 2008, 03:29 PM
Normal web service. I initially tried with WCF but it didn't work with the 3rd party web connector I have to use.
Arjay
October 16th, 2008, 03:51 PM
Normal web service. I initially tried with WCF but it didn't work with the 3rd party web connector I have to use.It's been a while since I've created a 2.0 web service, but I only created the service with classes and methods and the appropriate webservice/webmethod attributes. I never tried to use serialization as you are. Are you sure this is the correct approach?
richiebabes
October 17th, 2008, 08:41 AM
I don't know - I am new to this game. I need to grab data from our database and convert it into XML and have a web method return that XML. What's the best way to do that?
Arjay
October 17th, 2008, 09:03 AM
Create a web method that returns the xml string.
richiebabes
October 17th, 2008, 09:11 AM
:ehh: Well of course - that's obvious.
What I want to know is HOW TO CREATE THE XML STRING!! I have the class created using xsd.exe and I want to wrap it with the header stuff.
HOW DO I DO THAT?
I guess my question is with that serialization class what does it actually produce? How can I "get" the XML string out of it?
Arjay
October 17th, 2008, 09:42 AM
:ehh: Well of course - that's obvious.
What I want to know is HOW TO CREATE THE XML STRING!! I have the class created using xsd.exe and I want to wrap it with the header stuff.
HOW DO I DO THAT?
I guess my question is with that serialization class what does it actually produce? How can I "get" the XML string out of it?No need for the sarcasm. I'm suggesting that you are taking the wrong approach with xsd.exe, but you don't seem to hearing me.
public class MyService1 : System.Web.Services.WebService
{
[System.Web.Services.WebMethod( )]
public string GetXmlFromDb()
{
StringBuilder sb = new StringBuilder( );
//
// Insert sqlxml retrieval code here (and add to the string builder)
//
return sb.ToString( );
}
}
richiebabes
October 17th, 2008, 10:03 AM
I wasn't being sarcastic. Someone told me I had to use the xsd thing. But anyway - my question is HOW do I get the data from the database and put it into XML format easily?
Arjay
October 17th, 2008, 06:55 PM
I wasn't being sarcastic. Someone told me I had to use the xsd thing. But anyway - my question is HOW do I get the data from the database and put it into XML format easily?That wasn't the original question. No matter. You need to take a look at examples for the Microsoft.Data.SqlXml namespace. Btw, are you calling stored procedures?
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.