|
-
October 16th, 2008, 10:47 AM
#1
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?
-
October 16th, 2008, 01:24 PM
#2
Re: XML serialization problems
Anyone? Is my question not clear?
-
October 16th, 2008, 01:29 PM
#3
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?
-
October 16th, 2008, 01:46 PM
#4
Re: XML serialization problems
I am not sure what I am doing 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 . 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?
Last edited by Arjay; October 16th, 2008 at 02:19 PM.
Reason: Formatted so it's readable.
-
October 16th, 2008, 03:24 PM
#5
Re: XML serialization problems
 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?
-
October 16th, 2008, 03:29 PM
#6
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.
-
October 16th, 2008, 03:51 PM
#7
Re: XML serialization problems
 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?
-
October 17th, 2008, 08:41 AM
#8
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?
-
October 17th, 2008, 09:03 AM
#9
Re: XML serialization problems
Create a web method that returns the xml string.
-
October 17th, 2008, 09:11 AM
#10
Re: XML serialization problems
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?
-
October 17th, 2008, 09:42 AM
#11
Re: XML serialization problems
 Originally Posted by richiebabes
 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( );
}
}
-
October 17th, 2008, 10:03 AM
#12
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?
-
October 17th, 2008, 06:55 PM
#13
Re: XML serialization problems
 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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|