Navigation

    OpenIAP

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Working with XML

    General Discussion
    xml
    2
    7
    72
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      christian.schou1 last edited by

      Hello

      Are there any activities for working with XML? I would like to:

      1. Call an API that returns XML
      2. Deserialize XML
      3. Store the XML elements into variables
      4. Input variables in a data table based on some if statements

      Looking forward to hearing from you guys 🙂

      1 Reply Last reply Reply Quote 0
      • C
        christian.schou1 last edited by

        Hello again 🙂

        I have made the following in Node-RED:

        alt text

        My function looks like this:
        alt text
        My idea here is to assign the Orders object from JSON to orders.

        The generated JSON from the XML looks like the following:
        alt text

        My Robot looks like the following and have a variable with the name orders
        alt text

        How do I get the data from my function into the robot? I would like to insert the JSON data into a data table for iteration within the robot. Can someone see what I am doing wrong?

        Allan Zimmermann 1 Reply Last reply Reply Quote 0
        • Allan Zimmermann
          Allan Zimmermann @christian.schou1 last edited by Allan Zimmermann

          1. I don't think you can use $ as a name in json, so you need to clean it up
          2. if you you flattener your array data, you can get it as a data table ( the best solution. So arguement is of type System.Data.DataTable and you can then loop the data using "Foreach DataRow") )
          msg.payload = {"orders": [
          	{"id": "4976"},
          	{"id": "4978"}
          ]}
          

          I'm going to assume you intend on adding more info, so that makes sense. If all you are doing is sending a list of number/strings, you could also just set the type in the robot to Array of string and then use

          msg.payload = ["4976" "4978"]
          
          1. and lastly if you cannot or don't want to change the json structur you can simply parse the json in the robot, and set the argument type to Newtonsoft.Json.Linq.JObject ( or Newtonsoft.Json.Linq.JArray )
          msg.payload = {"orders": { blah blah }}
          

          Also, in your screenshot, you use Orders in the payload but orders with lowercase in the robot. Argument parsing from the payload object is case sensitive, so please always keep both in lowercase
          And don't use external hosts for images, you can paste images directly in to the edit box

          C 1 Reply Last reply Reply Quote 0
          • C
            christian.schou1 @Allan Zimmermann last edited by

            Hi @allan-zimmermann 👋

            Thank you very much for your reply and feedback. I managed to flatten the data and put it into an array and parse that to the robot. 😀

            I have made a Python script that converts the XML data in the future in order to generate a better format for the robot. The output is a JSON object which I don't think that OpenRPA supports (only JSON arrays)? I tried the ReadJSON activity but it asks for a JSON array and also wants to insert the data into a data table.

            Is it possible in OpenRPA to just deserialize the JSON object and use xdoc to assign specific elements/descendants from the JSON file to variables and then insert the descendants into a data table that way? I have made a similar thing in UiPath where I also made a for each that inserts elements from the serialized data into a data table.

            And I will paste the images into the editor next time - didn't know that was possible (way easier). 🙂

            Allan Zimmermann 1 Reply Last reply Reply Quote 0
            • Allan Zimmermann
              Allan Zimmermann @christian.schou1 last edited by Allan Zimmermann

              The idea of using an array with flat data, is you can add that to a data table.
              If you prefere working with an object instead, just set the argument in the robot to the type JObject ( I already mention this as 3. in my last reply. This also removes the need to "flatteren" the json, since JObject (or JArray ) supports any json )

              C 1 Reply Last reply Reply Quote 0
              • C
                christian.schou1 @Allan Zimmermann last edited by

                Hi @allan-zimmermann 👋

                I need it as an object as it got some header data I need during runtime 🙂

                My problem is: how can I work with JSON data in OpenRPA? What activity should I use? I had a look at the ReadJSON but I only take an array, isn't that correct, or is my understanding wrong here?

                Is it possible to use xdoc when assigning data?

                Best regards Christian

                Allan Zimmermann 1 Reply Last reply Reply Quote 0
                • Allan Zimmermann
                  Allan Zimmermann @christian.schou1 last edited by Allan Zimmermann

                  you are all over the place ... This thread is getting way to broad, please ask specific question or it's impossible to answer !

                  how can I work with JSON data in OpenRPA?

                  What do you mean ? I wouldn't know how to answer this, ask a specific question and I shall try an answer if I can.

                  What activity should I use?

                  Again, to WHAT ? I have no basis to answer on ... Use Invoke Code, Use Assign, Use ForEah ... there are millions right and/or right answers.

                  I had a look at the ReadJSON but I only take an array.

                  Yes, its for loading the data to a datatable ...

                  Is it possible to use xdoc when assigning data?

                  xdoc, as in XML ? you want to load json as xml ? that makes no sense ....

                  You can create a XDocument or XMLDocuement and load an xml string or xml file, and then use XPath to parse it
                  You can load JSon from a string using JObject.Parse(stringvar)
                  If you want to get from a file use System.Io.File.ReadAllText(filename) get the file content as a string

                  Hope it makes sense.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post