6 Replies Latest reply: Nov 19, 2012 11:25 AM by Jim.Marion-Oracle RSS

    Reading a Response XML

    846376
      Hi

      I have requirement to read a response xml file which is in the below format.

      <?xml version="1.0"?>
      <Response xmlns="http://hai" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <Dataa>
      <ArrayofChar>
      <string>Recno</string>
      <string>Personname</string>
      <string>Gender</string>
      <string>Age</string>
      </ArrayofChar>
      <ArrayofChar>
      <string>1000</string>
      <string>Harini Shankar</string>
      <string>F</string>
      <string>16</string>
      </ArrayofChar>
      <ArrayofChar>
      <string>1001</string>
      <string>Pavithira Shankar</string>
      <string>F</string>
      <string>15</string>
      </ArrayofChar>
      <string>1002</string>
      <string>Mridula</string>
      <string>F</string>
      <string>10</string>
      </ArrayofChar>
      </Data>
      </Response>
        • 1. Re: Reading a Response XML
          Jim.Marion-Oracle
          How are you receiving the file? HttpListeningConnector (Integration Broker) or as a file? If from Integration Broker, then access the XML document structure from the OnRequest handler message parameter. If from a file, use the CreateXmlDoc to create an XML Document and then load it through ParseXmlFromURL or ParseXmlString.
          • 2. Re: Reading a Response XML
            HakanBiroglu
            Have a look at this thread with an example PeopleCode on how to process an XML file
            {thread:id=2429699}
            • 3. Re: Reading a Response XML
              846376
              I am receiving the response through HttpListening connector. If we just look at the sample XML file that i have given, I may not be able to user GetElementsByTagName and retreive the values bcos the Column Names are given as node values as below:
              <ArrayofChar>
              <string>Recno</string>
              <string>Personname</string>
              <string>Gender</string>
              <string>Age</string>
              </ArrayofChar>

              the rest are values
              <ArrayofChar>
              <string>1000</string>
              <string>Harini Shankar</string>
              <string>F</string>
              <string>16</string>
              </ArrayofChar>
              .......

              I just wanted to know is there any easier way of unparsing this kind of XML.

              Thanks
              Sudha
              • 4. Re: Reading a Response XML
                HakanBiroglu
                That is a pretty strange way of creating xml files. Actually it is an two dimensional array transformed as an XML.

                What is the next step you want to do after reading the data? Based on that your XML reading code will be written.

                I would read the entire XML file and create a two dimensional PeopleCode array. Use the first node as the first index and the rest of the data as the second dimension. After this you can use the array methods like Find to get the second dimension (value) based on the first dimention ( column name)

                Hakan
                • 5. Re: Reading a Response XML
                  846376
                  Thanks Haken. I have started of with the code.. and i believe it will work.

                  -----
                  Sudha
                  • 6. Re: Reading a Response XML
                    Jim.Marion-Oracle
                    Is the order of the elements the same each time or do you have to use the headings to positionally identify the order of elements? If it is the same, you can use GetElementsByTagName to get an array of "ArrayofChar" elements or you can use FindNodes to return an array of XmlNode. The first element in the array would have your headings. The rest of the array would have data. You could loop over the remainder and process the rows. You can identify each of the string elements by index: GetChildNode(&idx). Your code would look something like this:
                    Local Array of XmlNode &rows = &xmlDoc.DocumentElement.FindNodes("/ArrayofChar");
                    Local number &rowIdx = 1;
                    
                    Local XmlNode &headingNodes = &rows[&rowIdx];
                    
                    While &rows.next(&rowIdx)
                       Local string &recNo = &rows[&rowIdx].GetChildNode(1).NodeValue;
                       Local string &personName = &rows[&rowIdx].GetChildNode(2).NodeValue;
                       ...
                       REM ** Process row;
                    End-While;
                    If the order can change, then loop over the &headingNode children using ChildNodeCount and GetChildNode.