XML serialization problems
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?
Re: XML serialization problems
Anyone? Is my question not clear?
Re: XML serialization problems
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?
Re: XML serialization problems
I am not sure what I am doing :blush: since I am new to this world. I have this, for instance, as a class:
Code:
[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:
Code:
<?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?
Re: XML serialization problems
Quote:
Originally Posted by richiebabes
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?
Re: XML serialization problems
Normal web service. I initially tried with WCF but it didn't work with the 3rd party web connector I have to use.
Re: XML serialization problems
Quote:
Originally Posted by richiebabes
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?
Re: XML serialization problems
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?
Re: XML serialization problems
Create a web method that returns the xml string.
Re: XML serialization problems
: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?
Re: XML serialization problems
Quote:
Originally Posted by richiebabes
: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.
Code:
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( );
}
}
Re: XML serialization problems
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?
Re: XML serialization problems
Quote:
Originally Posted by richiebabes
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?