Skip to Content
author's profile photo Former Member
Former Member

Change XML

Hi,

I write a BP to XML with SAVEXML.

Then I want to open this XML and change a value and read the XML again.

I cannot read this XML and get all kinds of errors.

What is the best method to change this XML?

Does anyone have a working example?

Kind regards,

John

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • Posted on Jul 05, 2007 at 10:18 PM

    I use the System.Xml.XmlDataDocument to manipulate xml... the reason why you might get errors is that you are using a wrong encoding with your reader... all SAP XML is encoded in Unicode (UTF16)

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 06, 2007 at 01:32 AM

    Hi John,

    Here's a piece of code I used to add contact details to the standard Order XML from SBO:

    private string AddOrderContactDetails(string sXML)
    {
    	string sName = "";
            string sTel = "";
            string sRetXML = "";
    
            XmlDocument xDoc = new XmlDocument();
            xDoc.LoadXml(sXML);
            XmlNode xOrder = xDoc.SelectSingleNode("//ORDR/row");
            XmlNode xCardCode = xDoc.SelectSingleNode("//CardCode");
            string sCardCode = xCardCode.InnerXml;
            XmlNode xCntctCode = xDoc.SelectSingleNode("//CntctCode");
            string sCntctCode = xCntctCode.InnerXml;
            if (sCardCode != "" && sCntctCode != "")
            {
               SAPbobsCOM.Recordset oRec = (SAPbobsCOM.Recordset)_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
               oRec.DoQuery("select [Name], Tel1 from OCPR where CardCode = '" + sCardCode + "' and CntctCode = " + sCntctCode);
               if (!oRec.EoF)
               {
               	sName = oRec.Fields.Item("Name").Value.ToString();
                    sTel = oRec.Fields.Item("Tel1").Value.ToString();
               }
               System.Runtime.InteropServices.Marshal.ReleaseComObject(oRec);
               GC.Collect();
            }
            XmlNode xNewNode = xDoc.CreateNode(XmlNodeType.Element, "CntctName", "");
            xNewNode.InnerXml = sName;
            xOrder.AppendChild(xNewNode);
            xNewNode = xDoc.CreateNode(XmlNodeType.Element, "CntctTel", "");
            xNewNode.InnerXml = sTel;
            xOrder.AppendChild(xNewNode);
    
            sRetXML = xDoc.OuterXml;
    
    	return sRetXML;
    }

    I call it using the Document.GetAsXML() method to generate the XML. I then use XLST to strip away all of the hundreds of nodes that I don't need that will be in the standard schema.

    Rasmus makes a very valid point about the encoding and also watch out for the XmlExportType property of the company object which defines the schemas used for export so you'll get different output for the same object depending on this setting.

    Kind Regards,

    Owen

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 10, 2007 at 03:36 PM

    Hi,

    When I write a XML with SDK.

    The XML starts like this:

    <?xml version="1.0" encoding="UTF-16" ?>

    - <BOM>

    - <BO>

    - <AdmInfo>

    <Object>2</Object>

    <Version>2</Version>

    </AdmInfo>

    - <BusinessPartners>

    - <row>

    <CardCode>C1000</CardCode>

    Now I read the XML into a dataset to change some data with:

    Dataset1.ReadXml(FileNameXML)

    When I write this data to XML with

    xmlDoc = New System.Xml.XmlDataDocument(Dataset1)

    it looks like this:

    <?xml version="1.0" encoding="utf-16" ?>

    - <BOM>

    - <BO>

    <BPPaymentMethods />

    <BPWithholdingTax />

    <BPPaymentDates />

    <BPBankAccounts />

    <BPFiscalTaxID />

    - <AdmInfo>

    <Object>2</Object>

    <Version>2</Version>

    </AdmInfo>

    - <BusinessPartners>

    - <row>

    <CardCode>C1000</CardCode>

    And I cannot read it anymore with SDK.

    How can I make my output-XML look like my input-XML?

    Kind regards,

    John.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 12, 2007 at 11:18 AM

    Nobody?

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi,

      To be able to read a saved xml file in DI API you have to set the property XmlExportType of the Company object you are connected to to BoXmlExportTypes.xet_ExportImportMode.

      Just have a look to this property and the different options in the HelpFile. It is specified there that you have to set this property to xet_ExportImportMode.

      Hope it helps

      Trinidad.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.