Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

XML comments

Tagged: ,

Return to Member Forum

  • Author
    Posts
    • #72701
      Aga Kluzik
      Member

      Is it possible to remove xml comments on import with a script? I know they can be added but I can’t find how to get rid of them…

    • #72815
      Anonymous
      Inactive

      Hi,

      You can definitively hide comments within InDesign. If you do want to remove them through Script, the best i to do load the file content as regular text and do the comments replacement. If you instantiate an XML object, chances are that you change the line breaks and get unexpected results within InDesign.
      Other solution is to use XSLT but it seems disproportionate.

      Loic

    • #72816
      Aga Kluzik
      Member

      I did manage to remove the comments – but as you said, I’m left with many empty lines :/
      But if I load the file as regular text – what will happen with the structure? I need the tekst to be mapped to different styles

    • #72817
      Anonymous
      Inactive

      HI Aga,

      The point is to load the file as text, do the comments removal then output the “cleared” file for import.

      function main() {
      var docs = app.documents,
      doc,
      f,
      nf,
      c,
      r = /<!–.+–>/g;

      if ( !docs.length ) return;

      f = File.openDialog(“Please select XML file”, function(f){ return /\.xml$/i.test(f.name) } );

      if ( !f ) return;

      f.open ( “r” );
      c = f.read();
      f.close();

      nf = new File ( Folder.temp+”/temp.xml” );
      nf.open(‘w’);
      nf.write ( c.replace (r, “” ) );
      nf.close();

      app.activeDocument.importXML ( nf );

      nf.remove();

      }

      main();

    • #72820
      Aga Kluzik
      Member

      OMG, thank you very much – I was struggling with this problem for some time, that seems to be exactly what I needed :)

      If I may exploit you bit more and ask for suggestion – the temporary xml file shows an error – not well-formed and the import is canceled. But after inspection the file seem to be ok and can be imported to InD – but all native font characters are gone…

    • #72821
      Anonymous
      Inactive

      It’s probably related to encoding. Feel free to send me the file through my website (contact) : https://www.ozalto.com

    • #72824
      Aga Kluzik
      Member

      Thank you, indeed the problem was with encoding and was solved with single line: nf.encoding = “UTF-8”.
      Thanks again.

    • #72825
      Anonymous
      Inactive

      Hi,

      Also on f.encoding. But that’s a presumption that the file encoding is actually UTF-8. If one uses another encoding, h will have to modify it.

      Loic

      Accueil

Viewing 7 reply threads
  • You must be logged in to reply to this topic.
Forum Ads