troubleshooting Question

Merge XML after existing XML to create QBXML FILE

Avatar of corey gashlin
corey gashlin asked on
XMLC#QuickBooksGolangSQL
2 Comments1 Solution116 ViewsLast Modified:
I have my code in C# to create the outershell of the file I need(QBXML).
I then have it call my function to query SQL and get the info that need to go inside of it under the <QBXMLMsgRq> element

The first part creates this -
<?xml version="1.0"?>
<?qbxml version="13.0"?>
<QBXML>
  <QBXMLMsgsRq onError="stopOnError" />
</QBXML>

Then it called my "BuildCustomerAddRq"

Which is this
 void BuildCustomerAddRq(XmlDocument doc, XmlElement parent)
    {

        try
        {
            string ConString = "Data Source=192.168.0.40;Initial Catalog=OCITIME;User ID=ocisql;Password=Emagdne1212";
            string CmdString = "select employee_name as Name ,'OCI Associates' as [CompanyName],'Mr' as Salutation , LEFT(employee_name, CHARINDEX(' ', employee_name + ' ') - 1) as FirstName,  REVERSE(LEFT(REVERSE(employee_name),    CHARINDEX(' ', REVERSE(employee_name)) - 1)) AS LastName   from EMPLOYEELIST for xml raw('CustomerAdd') , ROOT('CustomerAddRq'), ELEMENTS";

            SqlConnection con;
            SqlCommand cmd;
            XmlReader reader;
            XmlDocument xmlDoc;

            using (con = new SqlConnection(ConString))
            {
                cmd = new SqlCommand(CmdString, con);
                con.Open();
                reader = cmd.ExecuteXmlReader();
          

                while (reader.Read())
                {
             
                    doc.Load(reader);
                   
                }
                doc.AppendChild(doc.CreateXmlDeclaration("1.0", null, null));
                doc.AppendChild(doc.CreateProcessingInstruction("qbxml", "version=\"13.0\""));
                doc.Save("C:\\Employees.xml");
            }
        }
        catch (Exception)
        {
            throw;
        }


    }

Here is the build request that runs first -

//This is the shit to create requests and submit to QUICKBOOKS
    public ArrayList buildRequest()
    {
        XmlDocument requestXmlDoc = new XmlDocument();
        //Add the prolog processing instructions
        requestXmlDoc.AppendChild(requestXmlDoc.CreateXmlDeclaration("1.0", null, null));
        requestXmlDoc.AppendChild(requestXmlDoc.CreateProcessingInstruction("qbxml", "version=\"13.0\""));

        //Create the outer request envelope tag
        XmlElement outer = requestXmlDoc.CreateElement("QBXML");
        requestXmlDoc.AppendChild(outer);

        //Create the inner request envelope & any needed attributes
        XmlElement inner = requestXmlDoc.CreateElement("QBXMLMsgsRq");
        outer.AppendChild(inner);
        inner.SetAttribute("onError", "stopOnError");
        BuildCustomerAddRq(requestXmlDoc, inner);
       

        string strRequestXML = requestXmlDoc.OuterXml;
        req.Add(strRequestXML);
        requestXmlDoc.Save("C:\\testing123.xml");




        return req;
    }

I need it to spit something out like this -

<?xml version="1.0"?>
<?qbxml version="13.0"?>
<QBXML>
  <QBXMLMsgsRq onError="stopOnError">
    <CustomerAddRq requestID="1">
      <CustomerAdd>
        <Name>Fake Name</Name>
        <CompanyName>Fake Company</CompanyName>
        <Salutation>Mr.</Salutation>
        <FirstName>Fake</FirstName>
        <MiddleName>P</MiddleName>
        <LastName>Name</LastName>
        <JobTitle>Systems Engineer</JobTitle>
        <BillAddress>
          <Addr1>1234 Fake Address</Addr1>
        </BillAddress>
        <ShipToAddress>
          <Name>Fake Name</Name>
        </ShipToAddress>
        <Phone>123-126-123</Phone>
        <AltPhone>123-123-123</AltPhone>
        <Email>gashlin@gmail.com</Email>
      </CustomerAdd>
    </CustomerAddRq>
  </QBXMLMsgsRq>
</QBXML>


I know it has to be something simple but am drawing a blank.

Currently it is only giving me this

<CustomerAddRq>
  <CustomerAdd>
    <Name>Fake Name</Name>
    <CompanyName>Fake Company</CompanyName>
    <Salutation>Mr</Salutation>
    <FirstName>Fake</FirstName>
    <LastName>Name</LastName>
  </CustomerAdd>
</CustomerAddRq>

Looking to have them combined properly
ASKER CERTIFIED SOLUTION
corey gashlin

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros