CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    May 2004
    Posts
    474

    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?

  2. #2
    Join Date
    May 2004
    Posts
    474

    Re: XML serialization problems

    Anyone? Is my question not clear?

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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?

  4. #4
    Join Date
    May 2004
    Posts
    474

    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.

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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?

  6. #6
    Join Date
    May 2004
    Posts
    474

    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.

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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?

  8. #8
    Join Date
    May 2004
    Posts
    474

    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?

  9. #9
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: XML serialization problems

    Create a web method that returns the xml string.

  10. #10
    Join Date
    May 2004
    Posts
    474

    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?

  11. #11
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: XML serialization problems

    Quote 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( );
        }
    }

  12. #12
    Join Date
    May 2004
    Posts
    474

    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?

  13. #13
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured