Skip to content

Latest commit

 

History

History
206 lines (145 loc) · 4.97 KB

File metadata and controls

206 lines (145 loc) · 4.97 KB

🧹 Clean XML - XML Element Cleaner

Web application to process XML files and remove elements using a text. You can specify any text to target and remove specific elements from your XML files.

✨ Features

  • 🌐 Modern web interface with drag & drop
  • 📤 File upload via form or drag and drop
  • Real-time XML processing
  • 📥 Automatic download of processed file
  • File validation (XML only, max 50MB)
  • 🎨 Responsive design and easy to use

🚀 Installation

Prerequisites

  • Node.js v14 or higher
  • npm v6 or higher

Installation Steps

  1. Navigate to the project directory:

    cd clean-xml
  2. Install dependencies:

    npm install
  3. Start the server:

    npm start
  4. Open in browser:

    http://localhost:3000
    

📖 Usage

Command Line Interface (CLI)

You can use the script directly from the command line:

node clean-xml.js <input-file> <text> [output-file]

Examples:

# Automatic output filename (sample.xml -> sample.output.xml)
node clean-xml.js sample.xml "condition[property=\"City\"]"

# Custom output filename
node clean-xml.js sample.xml "condition[property=\"City\"]" custom-output.xml

# Remove all condition elements
node clean-xml.js sample.xml "condition"

Or using npm script:

npm run cli sample.xml "condition[property=\"City\"]"

Arguments:

  • input-file: Path to the input XML file (required)
  • text: Text for elements to remove (required)
    • Examples: condition[property="City"], condition[type="test"], condition
  • output-file: Path for the processed output XML file (optional)
    • If omitted, output will be automatically generated as [input-name].output.xml
    • Example: sample.xmlsample.output.xml

Web Interface

  1. Open the application in your browser (default: http://localhost:3000)
  2. Enter the text for elements you want to remove (e.g., condition[property="City"])
  3. Upload your XML file in one of these ways:
    • Click on the upload area and select a file
    • Drag and drop the XML file into the upload area
  4. Verify that the file has been selected correctly
  5. Click "Process File"
  6. The processed file will automatically download with the .output.xml suffix

API Endpoint

You can also use the endpoint directly:

curl -X POST http://localhost:3000/process \
  -F "xmlFile=@your_file.xml" \
  -F "text=condition[property=\"City\"]" \
  -o output_file.xml

🔧 Configuration

Environment Variables

You can configure the server port using the PORT environment variable:

PORT=8080 npm start

Limits

  • Maximum file size: 50MB
  • Accepted file types: .xml, application/xml, text/xml

📋 Functionality

The utility processes XML files and removes all elements matching the specified text. You can use any valid text to target specific elements.

Example 1 - Remove by property:

Before:

<profile>
  <condition property="City" value="Madrid" />
  <condition property="Age" value="25" />
  <condition property="City" value="Barcelona" />
</profile>

Text: condition[property="City"]

After:

<profile>
  <condition property="Age" value="25" />
</profile>

Example 2 - Remove all conditions:

Text: condition

This will remove all <condition> elements regardless of their attributes.

🛠️ Technologies Used

  • Express.js - Web framework for Node.js
  • Multer - Middleware for handling multipart/form-data files
  • JSDOM - DOM implementation for Node.js
  • HTML5/CSS3/JavaScript - Modern frontend

📁 Project Structure

clean-xml/
├── README.md           # This file
├── package.json        # Configuration and dependencies
├── server.js           # Express server and processing logic
├── clean-xml.js        # CLI script for command-line usage
├── public/             # Static files
│   └── index.html      # User interface
└── node_modules/       # Dependencies (generated)

🐛 Troubleshooting

Server won't start

  • Verify that port 3000 is not in use
  • Make sure all dependencies are installed (npm install)

Error processing file

  • Verify that the file is a valid XML
  • Check that the file size does not exceed 50MB
  • Check the server console for more error details

File won't download

  • Verify your browser's automatic download settings
  • Some browsers may require permission to download files

📝 Available Scripts

  • npm start - Start the web server in production mode
  • npm run dev - Start the web server (alias for start)
  • npm run cli - Run the CLI script (requires arguments: input-file text [output-file])

🔒 Security

  • Files are processed in memory and not stored on the server
  • Strict file type validation
  • File size limit to prevent abuse

📄 License

MIT

👤 Author

Node.js utilities project


Version: 1.0.0
Last updated: January 2026