Highlighted
Absent Member.
Absent Member.
337 views

[archive] Getting FilePath from a XML File

[Migrated content. Thread originally posted on 16 August 2007]

I having some trouble getting the FilePath from a XML file.

Here is my XML File (test.xml)


C:\Program Files\OutlookMailsBackup\PdfAndZipFiles\test.pdf
Re: Fw: short keys in CSPCT
RECEIVED
01/31/2007






Here is the code that I am using in my program to get information from the XML file


CALL "C$XML" USING CXML-PARSE-FILE, test.xml.
MOVE RETURN-CODE TO PARSER-HANDLE.
CALL "C$XML" USING CXML-GET-FIRST-CHILD, PARSER-HANDLE.
MOVE RETURN-CODE TO ELE-1-HANDLE.
*Get the File Path and Name
CALL "C$XML" USING CXML-GET-SIBLING-BY-NAME, ELE-1-HANDLE, "FilePath", 0.

MOVE RETURN-CODE TO ELE-2-HANDLE.
CALL "C$XML" USING CXML-GET-DATA, ELE-2-HANDLE, WS-NOTHING, WS-FILE-PATH.

*Get the Subject
CALL "C$XML" USING CXML-GET-SIBLING-BY-NAME, ELE-1-HANDLE, "Subject", 0.

MOVE RETURN-CODE TO ELE-2-HANDLE.
CALL "C$XML" USING CXML-GET-DATA, ELE-2-HANDLE, WS-NOTHING, WS-SUBJECT.

*Get the Date
CALL "C$XML" USING CXML-GET-SIBLING-BY-NAME, ELE-1-HANDLE, "Date", 0.

MOVE RETURN-CODE TO ELE-2-HANDLE.
CALL "C$XML" USING CXML-GET-DATA, ELE-2-HANDLE, WS-NOTHING, WS-DATE.


I am able to get the Subject and the Date just fine, but it will not get the FilePath. What am I doing wrong?
0 Likes
4 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Getting FilePath from a XML File

Hi Matt.,

I could be wrong, but I suspect you are getting the FilePath element when you use the GET-FIRST-CHILD syntax, and then you try to find another SIBLING with the same name, which isn't there (there's only one FilePath in your data, not two).

I've always found it best to parse the XML file by reading an element, and then determining what it is and how to process it - rather than requesting specific elements by value in sequence. Unless you've created the file, you can't be certain that the data you require is there, let alone the sequence that the items will be in.

So I process XML files in a loop, getting each element in turn and dealing with each one on face value - i.e. what is it and how do I process it. Something like:-GET-FIRST-CHILD
PERFORM TEST AFTER UNTIL RETURN-CODE = ZERO
   GET-XML-DATA
   EVALUATE DATA
      WHEN "FilePath"
        Do something
      WHEN "Subject"
        Do something else
      WHEN ....
        ......
      WHEN OTHER
        Ignore unexpected data
   END-EVALUATE
   GET-NEXT-XML-ITEM
END-PERFORM
As you're processing each XML element, you can tick-off flags to indicate you've received and dealt with required items. When you've finished parsing the file, you check that all flags have been ticked-off to indicate you have all the necessary data. Any flag not ticked off tells you which element was missing from the XML input.

Hope that helps 🙂

Ian
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Getting FilePath from a XML File

I thought was the first child and then all the other were siblings for that Child.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Getting FilePath from a XML File

I looks to me as though FilePath is a child of EmailInfo.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Getting FilePath from a XML File

Hi,

I tend to agree with Rob. The get-first-child will return FilePath, which is a sibling to all the other elements. EmailInfo is the parent to them all.

I've attached a sample program from Acucorp that really helped me come to terms with C$XML. I hope it helps you too 🙂

Regards,

Ian
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.