?
Solved

How would you do this (or would you at all)

Posted on 2005-04-26
4
Medium Priority
?
257 Views
Last Modified: 2013-12-24
i'll preface this by saying i know i can accomplish this by creating the xml from a loop ..am doing that for the non sensitive parts... but i don't want to store this info to the db if i can avoid it. The file is created above the webroot for added protection....

i have some data created with

<cffile action = "append"
file = "/beta/admin/xml/#dateformat(now(), "mmddyyyy")#.cfm"
output = "#varComment1#,#encrypted#,#varExpDate#,#varAmt#"
addnewline="yes"
>

which creates

4EF16D58-08E9-F63A-CD429E84CA31B921,0,N0*',[.[0/5]A6-3>!NKP,0906,$90.55

what i want to do is get them into xml format

<root>
  <order>
      <orderid>17FE9614-02D6-AC09-9885D8E574D85E22</orderid>
      <ccnum><![CDATA[0,N *'<[*[@-6_!45.6N3JK]]></ccnum>
      <expdate>0408</expdate>
      <amt>72.78</amt>
   </order>
</root>

thought about writing xml with the cffile but that gives me multiple <roots> and borks my import.

splitting up the string seems a difficult issue as the encrypted string seems to contain virtually all delimiters

i suppose i could

check if the file exists
 cffile append <root>
check if the file exists
cffile append
 <order>
      <orderid>17FE9614-02D6-AC09-9885D8E574D85E22</orderid>
      <ccnum><![CDATA[0,N *'<[*[@-6_!45.6N3JK]]></ccnum>
      <expdate>0408</expdate>
      <amt>72.78</amt>
   </order>
...etc
then when i grab the file
check if the file exists
 cffile append </root>

seems kinda kludgy...(but some call me the king of kludge ;)

anyone have any ideas...





0
Comment
Question by:SidFishes
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
INSDivision6 earned 1500 total points
ID: 13871694
Not sure that your <ccnum> node is correct from XML point of view, but this is a different issue....

About your file creation approach.  We, actually, have a similar problem.  We need to append a file with some data that depends on the info at the end of the file.  We use this tag:

http://www.cftagstore.com/tags/cfxexec.cfm

It allows: (1) reading a portion of file at certain position relatively to the start or to the end of the file; (2) writing to the file at arbitrary position.  Therefore, you do not need to read the entire file.  So, if you under Windows, you always can keep your file in order:

<root>
   <order>
   </order>
. . . . .
   <order>
   </order>
</root>

When appending the new <order>, you just write at the begining of </root> (wich is position 6 from the end).  Obviously, you always terminate new <order> with </root>.

We do similar trick with rather big (>2MB) daily data invoice file.

0
 
LVL 36

Author Comment

by:SidFishes
ID: 13872004
afaik the ccnum is fine as it is enclosed in  CDATA ...it's the only way to use non xml compliant characters and since these are encrypted they are going to have non standard characters (at least this is what i have gleaned from EE and besides it works ;)

i'll have a look at the tag ...sounds promising

thx
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 13872546
To append data to the XML you need to read the file, parse the XML and then add the data programatically.

Not 100% sure what you want to do to be honest with you ;-)

0
 
LVL 36

Author Comment

by:SidFishes
ID: 13877622
i looked at the tag but cfx's aren't great for hosted sites....soo

i threw together this custom tag

<!---
Custom Tag By SidFishes April 26, 2005
More at www.sidfishes.net
You are free to use or modify as you wish as long as you give
originating credit and buy me a coffee if we meet at an airport ;)

<cf_AppendXML
            AbsFilePath = ""
            RelFilePath = ""
            OrderID  = ""
            CCNum    = ""
            ExpDate  = ""
            Amt      = ""      
            >
--->


<cfset filedate ="#dateformat(now(), "mmddyyyy")#">
<cfif NOT isdefined('Attributes.AbsFilePath')>
      <cfabort showError="AbsFilePath is required.">
</cfif>

<cfif NOT isdefined('Attributes.RelFilePath')>
     <cfabort showError="RelFilePath is required.">
</cfif>

<cfif NOT isdefined('Attributes.OrderID')>
    <cfabort showError="OrderID is required.">
</cfif>

<cfif NOT isdefined('Attributes.ccnum')>
    <cfabort showError="CCNum is required.">
</cfif>

<cfif NOT isdefined('Attributes.ExpDate')>
    <cfabort showError="ExpDate is required.">
</cfif>

<cfif NOT isdefined('Attributes.Amt')>
   <cfabort showError="Amt is required.">
</cfif>

<cfset FileName = Attributes.AbsFilepath & filedate & ".cfm">

<cfif NOT FileExists(fileName)>
<!--- Then It's New  so add a header --->
<cfsavecontent VARIABLE="XML_1">
<cfoutput>
<root>
      <order>
            <orderid>#Attributes.OrderID#</orderid>
            <ccnum><![CDATA[#Attributes.ccnum#]]></ccnum>
            <expdate>#Attributes.ExpDate#</expdate>
            <amt>#Attributes.Amt#</amt>
      </order>
</root>
</cfoutput>
</cfsavecontent>

<!--- write to disk --->
<cffile action="WRITE"
                  file="#Attributes.AbsFilePath##dateformat(now(), "mmddyyyy")#.cfm"
                   output="#XML_1#" nameconflict="Overwrite">

<cfelse>
<!--- we already have a file --->

<cfset existingFile = Attributes.RelFilePAth & filedate & ".cfm">

<cfsavecontent Variable="XML_1">
<!--- Read the file content to a variable --->
<cfinclude template= #ExistingFile#>
</cfsavecontent>
<!--- Replace the last XML tag --->
<cfset XML_1 = Replace(XML_1, "</root>", "", "all")>

<!--- create the string for the append - include the new </root> --->
<cfsavecontent variable="XML_2">
<cfoutput>
        <order>
            <orderid>#Attributes.OrderID#</orderid>
            <ccnum><![CDATA[#Attributes.ccnum#]]></ccnum>
            <expdate>#Attributes.ExpDate#</expdate>
            <amt>#Attributes.Amt#</amt>
      </order>
</root>
</cfoutput>
</cfsavecontent>

<!--- Create the new merged variable --->
<cfsavecontent variable="XML_Appended">
<cfoutput>
#XML_1#
#XML_2#
</cfoutput>
</cfsavecontent>

<!--- write to disk --->
<cffile action="WRITE"
                  file="#Attributes.AbsFilePAth##dateformat(now(), "mmddyyyy")#.cfm"
                   output="#XML_Appended#" nameconflict="Overwrite">

</cfif>


Works exactly as I wanted... :)

I'll give INDivision the points as it was a solution...just not one for me
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
What You Need to Know when Searching for a Webhost Provider
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question