logo
down
shadow

How can I remove all comments from a large XML file?


How can I remove all comments from a large XML file?

By : user2948356
Date : November 14 2020, 04:51 PM
fixed the issue. Will look into that further Assuming Xslt is an option, you can use a modified version of the identity transform which will project nothing for any matched comment:
code :
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="comment()"/>

</xsl:stylesheet>


Share : facebook icon twitter icon
Remove comments and write to new text file without comments

Remove comments and write to new text file without comments


By : Manu Thakur
Date : March 29 2020, 07:55 AM
will be helpful for those in need i need to make a program where the input file is a source code with comments and output is the same code without comments. , to solve your problem you'll have to user preg_replace
code :
    $notCommentedFile = preg_replace('/#.*/', '', $commentedFile);
    $notCommentedFile = preg_replace('#//.*#', '', $notCommentedFile);
    $notCommentedFile = preg_replace('#/\*(?:[^*]*(?:\*(?!/))*)*\*/#', '', $notCommentedFile);
How to improve xerces parser performance when large comments are present in xml file?

How to improve xerces parser performance when large comments are present in xml file?


By : RedBoool
Date : March 29 2020, 07:55 AM
around this issue The problem has been previously (well, more than 10 years ago) reported as XERCESJ-970. It has been fixed in revision 1507079 of xerces-j trunk since mid 2013.
The problem is a linearly growing buffer within XMLStringBuffer that too often needs to be reallocated.
Remove comments from large files using Java

Remove comments from large files using Java


By : SRC ECE B
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Turns out the biggest problem of my code was use of Strings. Reading lines by any method din't make much of a difference but using StringBuilder instead of String to store the uncommented line, changed the performance drastically. Now the same code with StringBuilder takes seconds to remove comments where it took hours earlier.
Here's the code. For better performance I've changed List to BufferedReader.
code :
/**
     * Removes all the commented part from the file content as well as returns a
     * file structure which have just lines with declaration syntax for eg.
     * Create Package packageName <- Stores all decalartion lines as separate
     * string in an array
     * 
     * @param file
     * @return file content
     * @throws IOException
     */
    private static List<String> filterContent(File file) throws IOException {

        StringBuilder withoutComment = new StringBuilder();
//      String declare = "";
//      String[] content;
//      List<String> readLines = FileUtils.readLines(file);
//
//      int size = readLines.size();
        System.out.println(file.getName() + "  at " + new Date());
        List<String> declareLines = new ArrayList<String>();
        // String line = null;
        int startComment = 0;
        int endComment = 0;
        Boolean check = false;
        Boolean isLineDeclaration = false;

        int j = 0;
        int i = 0;

        InputStream in = new FileInputStream(file);
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line;
        // Reading content line by line
        while ((line = reader.readLine()) != null) {
            // for (int i = 0; i < size; i++) {
            // line = readLines.get(i).toString();// storing current line data
            // If line contains */ that means comment is ending in this line,
            // making a note of the line number
            if (line.toString().contains("*/")) {
                endComment = i;
                // Removing the content before */ from the line
                int indexOf = line.indexOf("*/");
                line = line.replace(line.substring(0, indexOf + 2), "");
            }

            // If startComment is assigned fresh value and end comment hasn't,
            // that means the current line is part of the comment
            // Ignoring the line in this case and moving on to the next one
            if ((startComment > 0 && endComment == 0) || (endComment < startComment) || check)
                continue;

            // If line contains /* that means comment is starting in this line,
            // making a note of the line number
            if (line.contains("/*")) {
                startComment = i;
                // Removing the content after /* from the line
                int indexOf = line.indexOf("/*");
                line = line.replace(line.substring(indexOf), "");
                if (i == 0)
                    check = true; // means comment in the very first line
            }

            // If line contains -- that means single line comment is present in
            // this line,
            // removing the content after --
            if (line.contains("--")) {
                int indexOf = line.indexOf("--");
                line = line.replace(line.substring(indexOf), "");
            }
            // If line contains -- that means single line comment is present in
            // this line,
            // removing the content after --
            if (line.contains("#")) {
                int indexOf = line.indexOf("#");
                line = line.replace(line.substring(indexOf), "");
            }

            // At this point, all commented part is removed from the line, hence
            // appending it to the final content
            if (!line.isEmpty())
                withoutComment.append(line).append(" \n");
            // If line contains CREATE its a declaration line, holding it
            // separately in the array
            if (line.toUpperCase().contains(("CREATE"))) {
                // If next line does not contains Create and the current line is
                // the not the last line,
                // then considering two consecutive lines as declaration line,
                declareLines.add(line.toUpperCase());

                isLineDeclaration = true;
                j++;
            } else if (isLineDeclaration && !line.toUpperCase().contains(("CREATE"))) {
                // If next line does not contains Create and the current line is
                // the not the last line,
                // then considering two consecutive lines as declaration line,
                declareLines.set(j - 1, declareLines.get(j - 1) + " " + line.toUpperCase());
                isLineDeclaration = false;
            }
            i++;
        }

        reader.close();
        System.out.println("Read lines " + new Date());
//      List<String> list = new ArrayList<String>(Arrays.asList(declareLines));
        declareLines.removeAll(Collections.singleton(null));

//      content = list.toArray(new String[list.size() + 1]);

//      withoutComment = withoutComment..toUpperCase();
        declareLines.add(withoutComment.toString().toUpperCase());
        System.out.println("Retruning uncommented content " + new Date());
        return declareLines;
    }
Deleting comments in a large file

Deleting comments in a large file


By : Muhammad Burhan Zahi
Date : March 29 2020, 07:55 AM
Any of those help Instead of trying to cram this into one complex regex, it's much easier to search for the start of a comment and delete from there on to the end of a comment
code :
:g/^\/\*\*$/,/\*\/$/d_
:g               start a global command
/^\/\*\*$/       search for start of a comment: <sol>/**<eol>
,/^\*\/$/        extend the range to the end of a comment: <sol>*/<eol>
d                delete the range
_                use the black hole register (performance optimization)
Looking to remove comments from a large amount of javascript files

Looking to remove comments from a large amount of javascript files


By : KyawPh Han
Date : March 29 2020, 07:55 AM
With these it helps Take a closer look at uglifyjs. It neither compresses nor munges by default (you have to give the -c and -m options, respectively), and you can choose in fine detail what kinds of compression it does, even to the level of specifying a regular expression for what kinds of comments to remove. And, you can even pretty print on the way out, if you're so inclined. So what's the problem with using it?
Related Posts Related Posts :
  • How to add Smarty templating engine to CodeIgniters 3 framework?
  • Am I maxing out possible data insert
  • Redirect to homepage without changing address bar URL
  • What is the best user-Id Value for a MySql "users" table
  • PHP $_COOKIE is only available in one directory
  • php regular expressions documantation
  • cannot import too large sql file to mysql
  • not getting appilcation/json in content-type in header
  • Only the first data display from my database but other shows but not on a table
  • Is it possible to have a print button link as the content of the mail
  • how to extract full mail address in imap php
  • Alternative to output buffering to put eval'd code into a variable
  • how to run wordpress php snippet mysql update command from ssh and/ultimately cron
  • how to get xml tag by name
  • ModSecurity maximum post limits (PCRE limit errors)
  • Call controller/action in event listener
  • How to improve performance of contacting WebService?
  • PHP nest variable in echoed string that contains a HTML tag in the end
  • Multiple Ajax request for PHP framework
  • Debug Info from Moodle Plugin
  • passing variables through page
  • Passing PHP $result data to Javascript
  • cakePHP File Download was not found or not readable
  • batch waiting until script finishes
  • PHP variables and anchors in URL
  • php eTag generation using php
  • How to check whether the array is an Integer or Not?
  • Is it possible to install Doctrine without PEAR or Composer? If so, how?
  • Call view script of (parent) Abstract controller Zend
  • Curl PHP cannot display amazon
  • Symfony, getters and setters vs magic methods
  • Using 'continue' PHP instruction outside the loop
  • AJAX POST return data not appearing
  • Can I query relations using an INNER JOIN instead of two queries in Eloquent?
  • Looping through dynamic form fields and inserting into database
  • My php code can't select mysql auto_increment value
  • Store Angularjs form data in database using php
  • I want to run my sh file continuously even if I close my Putty connection
  • file_get_contents equivalent for gzipped files
  • Include PHP file with jQuery
  • php curl headers do not return from website?
  • How to find out, if facebook ID is a user, group or page
  • Connect webhost database to android database
  • preg_match get div content with class
  • Upload multiple files in Laravel 4
  • Count array numbers in multidimensional array
  • PHP Date diff with a difference
  • Search Customer by custom field in Netsuite
  • Is it possible to hide/encode/encrypt php source code and let others have the system?
  • list items to be displayed using php code and array
  • check if row exists mysqli
  • PHP errors loading MySQL
  • setup PostgreSQL with Laravel in MAMP
  • PHP - CodeIgniter Notifications
  • Encrypting a password column in a SQL database
  • New to PHP, trying to extract information from another website
  • JavaScript AmChart to Image for Email
  • Is javascript validation enough to keep my forms secure?
  • Regex extract variables from [shortcode]
  • Download a .mp3 link and save it to computer with PHP
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org