File creation problems

Ask a Question related to Macromedia Exchange Dreamweaver Extensions, Design and Development.

  1. #1

    Default File creation problems

    Hi,
    I'm pretty new at writing extensions so I'm quite certain my problem is a
    mistake on my part.
    I've written a piece of code that takes a data file and formats it into a
    table and writes the table to a new file (the client doesn't want to use
    templates, that's why it's done this way).
    The data file is formatted with the first line as the page title, the second
    line has the column names and the rest is the data. The data if formatted with
    ";"
    The function doStuff calls the fixTag function.

    Whenever I run this, the contents of the data file (opened with fh =
    dreamweaver.openDocument(theFile); in the fixTag function) receives the data I
    try to write to the new file (created with var newTableDoc =
    dreamweaver.createXHTMLDocument(); in the doStuff function).

    What am I doing wrong here. I've tried using dreamweaver.releaseDocument to
    release the data file, but it doesn't help. I've tried creating the new file
    with dreamweaver.getNewDocumentDOM but can't figure out how to then save that
    without running into the same overwrite problem.
    Any help, tips, and the like is greatly appreciated.

    Problem code is attached.


    function doStuff(){
    var siteFocus,agree,chooseFiles,fileSelect;
    var alertMessage = "";
    var rString;

    var siteSelectedArray = new Array();
    var writeSiteSelectedArray = new Array();
    var urlArray = new Array;
    var siteFocus = site.getFocus();
    urlArray = dw.getDocumentPath("document");

    rString = fixTag(urlArray);
    var newTableDoc = dreamweaver.createXHTMLDocument();
    newTableDoc.getElementsByTagName("body")[0].innerHTML = rString;
    // alert(newTableDoc.documentElement.outerHTML);
    }

    function fixTag(theFile,autoSave){
    var fh;
    var fileLines;
    var splitLines = new Array;
    var stateBody = new Array;
    var stateName = "none";
    var metaTags;
    var repeated = "0";
    var returnString="";
    var pageHeading, tableHeadings, tableContent;
    var tableEnd = "</table>\n";
    fh = dreamweaver.openDocument(theFile); // Open the file for reading
    fileLines = fh.documentElement.outerHTML.split("\n");
    for (i = 1;i<fileLines.length;i++){
    splitLines[i]=fileLines[i].split(";");
    }
    dreamweaver.releaseDocument(fh);
    // heading of page
    pageHeading = "<h1>" + fileLines[0] + "</h1>\n";
    // Generate table header
    tableHeadings = "<thead>\n<tr>\n";
    for (i=1;i<splitLines[1].length;i++){
    tableHeadings += "<th>" + splitLines[1][i] + "</th>\n";
    }
    tableHeadings += "</tr>\n</thead>\n";

    for (i=2;i<splitLines.length-1;i++){
    if (!stateBody[splitLines[i][0]]){
    stateBody[splitLines[i][0]] = "";
    }
    stateBody[splitLines[i][0]] += "<tr>\n";
    for (j=1;j<splitLines[i].length;j++){
    stateBody[splitLines[i][0]] += "<td>" + splitLines[i][j] + "</td>\n";
    }
    stateBody[splitLines[i][0]] += "</tr>\n";
    }
    returnString += pageHeading;
    for (i in stateBody){
    returnString += "<table>\n <caption>" + i + "</caption>\n" + tableHeadings +
    "<tbody>\n" + stateBody[i] + "</tbody>\n</table>\n";
    }

    return returnString;

    }

    four-ks Guest

  2. Similar Questions and Discussions

    1. XML File creation
      I am generating xml output from a cfquery. <cfxml variable="Contact" casesensitive="yes"> <Contact> <cfoutput query="GetName"> <phonenum...
    2. Form creation problems
      Hi I am trying to make a "create new user" form where people will enter their info to create a user name and password. The information would then...
    3. pdf creation problems
      I am opperating on Win 2000 using freehand mx. I am trying to create a PDF file through Distiller (Acrobat 4.0). I save the freehand file as a eps...
    4. [Q] Image Creation problems & MacOSX
      I've got a fairly simple php script which creates a simple gif image. Now, if I use this script on my primary webhost, everything works correctly...
    5. linux boot CD creation problems
      Hi all, I have a dual boot machine (XP + RH 7.3). I have not installed any boot loaders and get into linux thru a boot floppy. (My boot sequence...
  3. #2

    Default Re: File creation problems

    Almost forgot some important details.
    Dreamweaver MX 2004 running on win 2k system.
    four-ks Guest

  4. #3

    Default Re: File creation problems

    Found the solution. Was my poor coding.
    I just need to have

    dreamweaver.createXHTMLDocument();
    newTableDoc=dreamweaver.getActiveWindow();
    newTableDoc.getElementsByTagName("body")[0].innerHTML = rString;

    hope this helps someone else.

    Cheers.

    four-ks Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139