Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #18584

    slav
    Participant

    Is it possible to setup EmEditor to automatically determine if opened file is XML document, regardless of extension, and apply XML scheme.

    Any XML document would have
    <?xml version=”1.0″ encoding=”utf-8″?> (encoding could be different)
    as 1st line.

    So, in theory, it should be very easy to determine just by looking at 1st line.

    #18585

    Stefan
    Participant

    Hi slav.
     

    You could utilize a macro script for that, which acts on event “File Opened”

     

    Steps:
    – save the macro as “DetectXML.jsee” to your EmEditor folder (I have a sub folder “Macros” created for that use)
    – utilize “Macros > Select…” and select this new macro file to add it to MyMacros category.
    – chose “Macros > Customize…”
    – select the macro (at the end of the list),
    – enable “[x] Run at Events”
    – press at [Events…] and chose “[x] File Opened”
    – ok
    – ok
    Test by opening an file containing XML structured text but lacks the XML extension (or not)

     

    The macro:
    (you may want to delete the “alert()” lines)
     

    if (document.selection.Find("<?xml",eeFindNext)){
    alert ('xml file detected'); //this line can be delete
    alert("Current Configuration: " + document.ConfigName); //line can be delete
    document.ConfigName = "XML"; //switch configuration to XML
    alert("Configuration switched to: " + document.ConfigName); //line can be delete
    }
     
      
    
    

    Could be improved with
    strFirstLine = document.GetLine( 1 );       if strFirstLine.indexOf(“<?xml”)…..
    to detect at top of document only.
     
    .

    #18586

    slav
    Participant

    Works great, thank you very much.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.