Skip to main content

[archive] Getting FilePath from a XML File

  • August 17, 2007
  • 6 replies
  • 0 views

[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?

6 replies

[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?
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

[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?
I thought was the first child and then all the other were siblings for that Child.

[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?
I looks to me as though FilePath is a child of EmailInfo.

[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?
I looks to me as though FilePath is a child of EmailInfo.

[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?
I looks to me as though FilePath is a child of EmailInfo.

[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?
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