JadeXMLDocument delete

For questions and postings not covered by the other forums
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

JadeXMLDocument delete

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:12 pm

by CassMan >> Wed, 3 Oct 2007 14:45:31 GMT

Hi again,

I have a program which firsts creates an XML tree and then writes it to a file using the WriteToFile method. This, obviously, creates a physical file at the directory that is specified as a parameter. However, i don't like having this as a physical, permanent file as it is only needed temporarily whilst the program is running.

Is there any command for erasing a document at the end of a program? The ' delete <File> ' command simply deletes the reference to it - the file still exists.

The File is actually a JadeXMLDocument btw.

Thanks,

Rich

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: JadeXMLDocument delete

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:12 pm

by Torrie Moore >> Wed, 3 Oct 2007 21:13:16 GMT

Hi Rich

If you have a file on disk, it can be deleted using the File::purge method. e.g.

vars
oFile : File;
begin
create oFile transient;
oFile.fileName := "c:\temp\clientpic2143.2.jpg";

// Remove this file from disk.
oFile.purge;
epilog
delete oFile;

Regards

Torrie

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: JadeXMLDocument delete

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:12 pm

by CassMan >> Thu, 4 Oct 2007 9:05:40 GMT

Hi Torrie,

I have seen the purge method used a few times but never really understood what it did! :-/. Can this be used with JadeXMLDocuments? Or is it just instances of File?

Regards,

Rich x

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: JadeXMLDocument delete

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:12 pm

by CassMan >> Thu, 4 Oct 2007 15:47:50 GMT

I have a further question.

I need to send the XML over to a gateway. The first line of the xml is:

<GovTalkMessage xmlns="http://www.govtalk.gov.uk/CM/envelope">

When i have this typed out in a file, and call "parseFile", this works perfectly ok. However, if i create the elements myself then the output is fine and legal, but it still throws the following error:


<Error>
<RaisedBy>System</RaisedBy>
<Number>1001</Number>
<Type>fatal</Type>
<Text>The element 'Header' in namespace 'http://www.govtalk.gov.uk/CM/envelope' has incomplete content. List of possible elements expected: 'MessageDetails' in namespace 'http://www.govtalk.gov.uk/CM/envelope'.
</Text>
<Location/>
</Error>
</GovTalkErrors>
</GovTalkDetails>
<Body></Body>
</GovTalkMessage>


Does anybody know how to fix this error?! I know it must have something to do with the namespace. I am using

addElementNS('http://www.govtalk.gov.uk/CM/envelope', "GovTalkMessage").

It creates it fine, but does not work.

Any ideas?

Rich

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: JadeXMLDocument delete

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:12 pm

by Dave Patrick >> Fri, 5 Oct 2007 1:33:09 GMT

Rich,

Are you trying to use the addElementNS to set the "xmlns=" portion of your XML header? This doesn't work quite the way the JADE documentation would have you believe (in fact, it doesn't work at all).

To get a xmlns statement in your XML header, you need to use addAttribute instead - so if you had something like

xmlDoc.addElementNS("http://www.govtalk.gov.uk/CM/envelope", "GovTalkMessage")

you actually need something like

element := xmlDoc.addElement("GovTalkMessage"); element.addAttribute("xmlns", "http://www.govtalk.gov.uk/CM/envelope");

This will produce a header of
<GovTalkMessage xmlns="http://www.govtalk.gov.uk/CM/envelope">

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: JadeXMLDocument delete

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:12 pm

by CassMan >> Wed, 17 Oct 2007 13:21:58 GMT

Hi John,

Thanks for the info. That worked fine :-).


Regarding the original problem, i researched into not using temporary XML files, as Dave suggested and i managed to do this using simply global strings. The reason i initially believe i needed temp files is that i needed to use the files at different stages, but not after the program had been run....

Cheers,

Cass

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: JadeXMLDocument delete

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:12 pm

by John Munro >> Thu, 4 Oct 2007 19:08:09 GMT

File::purge deletes the file represented by the File object from the hard drive.

I imagine it's not named 'delete' because that keyword is already used in the context of deleting objects.

Purge can delete any file (assuming they're not read-only or in use and you have file access permissions), not just XML documents.

Just to be clear, JadeXMLDocument is a class that represents an XML tree in memory. When you call writeToFile, it creates a file on the hard drive that represents the XML. The JadeXMLDocument object and the file on the hard drive aren't really connected - deleting the object using the delete keyword doesn't affect the file and deleting the file using purge doesn't affect the object in memory.

Incidentally, why do you temporarily need the XML file on the hard drive?

John


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 21 guests