Home > Net >  Azure Logic App: Is it possible to send a XML File via HTTP Request and then save it as an .xml File
Azure Logic App: Is it possible to send a XML File via HTTP Request and then save it as an .xml File

Time:09-20

I have been trying to create an Azure Logic App, which takes an .xml File and saves/creates it in my OneDrive Account (I do not know a lot about http requests, json files or anything similar). At the time I'm writing this, I've got the connection to my OneDrive to save an empty .xml File.

Now I'll need your help for saving the file with raw data. The xml structure I would want to save, is always split into multiple parts.

The NAV_Header part only appears once, yet the NAV_Line part can appear multiple times.

<Root>
  <NAV_Header>
    <Customer>BIBA</Customer>
    <Stylesheet>NAV_CH_PROD/item-label.xsl</Stylesheet>
    <Separate_FOP_Config>0</Separate_FOP_Config>
    <User_ID>BOSSINFO\SMUELLER</User_ID>
    <Output_Option>0</Output_Option>
    <Output_Path />
    <Printer_Name />
    <Windows_Printer>0</Windows_Printer>
  </NAV_Header>
  <NAV_Line>
    <Item_Description>Kolben DN 10-15 H-PVC</Item_Description>
    <Item_No>123456789012</Item_No>
      <Item_No_Lbl>Artikel Nr.: </Item_No_Lbl>
    <Order_No>51062579</Order_No>
    <Order_No_Lbl>Bestell Nr.: </Order_No_Lbl>
    <Amount>275</Amount>
    <Amount_Lbl>Amount: </Amount_Lbl>
  </NAV_Line>
</Root>

Thanks to everyone that can help me.

CodePudding user response:

Try following :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.IO;

namespace ConsoleApplication40
{
    class Program
    {
        const string INPUT_FILENAME = @"c:\temp\test.xml";
        const string OUTPUT_FILENAME = @"c:\temp\test.csv";
        static void Main(string[] args)
        {
            StreamWriter writer = new StreamWriter(OUTPUT_FILENAME);
            XDocument doc = XDocument.Load(INPUT_FILENAME);

            XElement xNavHeader = doc.Root.Element("NAV_Header");

            string[] navHeaders =  {"Customer", "Stylesheet", "Separate_FOP_Config", "User_ID", "Output_Option", "Output_Path", "Printer_Name", "Windows_Printer"};

            writer.WriteLine(string.Join(",", navHeaders));
            string[] navData = navHeaders.Select(x => (string)xNavHeader.Element(x)).ToArray();
            writer.WriteLine(string.Join(",", navData));

            string[] navLineHeaders = { "Item_Description", "Item_No", "Item_No_Lbl", "Order_No", "Order_No_Lbl", "Amount", "Amount_Lbl" };
            writer.WriteLine(string.Join(",", navLineHeaders));

            foreach(XElement xNAV_Line in doc.Root.Descendants("NAV_Line"))
            {
                string[] navLineData = navLineHeaders.Select(x => (string)xNAV_Line.Descendants(x).FirstOrDefault()).ToArray();
                writer.WriteLine(string.Join(",", navLineData));
            }

            writer.Flush();
            writer.Close();

        }

    }
}
  • Related