This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.etree.ElementTree as ET | |
tree = ET.parse('books.xml') | |
root = tree.getroot() | |
for book in root.findall('book'): | |
if book.get('id') == '1': | |
book.find('price').text = '24.99' | |
tree.write('books.xml') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let xmlString = `<?xml version="1.0"?><books><book><title>XML Guide</title></book></books>`; | |
let parser = new DOMParser(); | |
let xmlDoc = parser.parseFromString(xmlString, "text/xml"); | |
console.log(xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.xml.parsers.*; | |
import org.w3c.dom.*; | |
import java.io.*; | |
public class ReadXML { | |
public static void main(String[] args) throws Exception { | |
File inputFile = new File("books.xml"); | |
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); | |
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); | |
Document doc = dBuilder.parse(inputFile); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.etree.ElementTree as ET | |
tree = ET.parse('books.xml') | |
root = tree.getroot() | |
for book in root.findall('book'): | |
title = book.find('title').text | |
author = book.find('author').text | |
price = book.find('price').text | |
print(f"Title: {title}, Author: {author}, Price: {price}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<books> | |
<book id="1"> | |
<title>Introduction to XML</title> | |
<author>John Doe</author> | |
<price>29.99</price> | |
</book> | |
<book id="2"> | |
<title>Advanced XML Techniques</title> | |
<author>Jane Smith</author> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pypdf import PdfReader, PdfWriter | |
# Paths for the input PDF and watermark PDF | |
input_pdf = "pdf-to-watermark/input.pdf" | |
watermark_pdf = "pdf-to-watermark/watermark.pdf" | |
output_pdf = "pdf-to-watermark/output_with_watermark.pdf" | |
# Read the input PDF and watermark PDF | |
reader = PdfReader(input_pdf) | |
watermark = PdfReader(watermark_pdf) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pypdf import PdfReader, PdfWriter | |
import os | |
# Input PDF file | |
input_pdf = "pdf-to-split/input.pdf" | |
# Output directory | |
output_directory = "pdf-to-split/output-dir" | |
# Ensure the output directory exists |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from pypdf import PdfReader, PdfWriter | |
# Directory containing PDF files | |
directory = "pdfs-to-merge" | |
# Output file name | |
output_file = "output-dir/merged_output.pdf" | |
# Ensure the output directory exists |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pypdf import PdfReader, PdfWriter | |
# Input and output PDF files | |
input_pdf = "pdf-to-rotate/input.pdf" | |
output_pdf = "pdf-to-rotate/rotated_output.pdf" | |
# Read the PDF | |
reader = PdfReader(input_pdf) | |
writer = PdfWriter() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Page 1: | |
Python Tutorial | |
Release 3.7.0 | |
Guido van Rossum | |
and the Python development team | |
September 02, 2018 | |
Python Software Foundation | |
Email: docs@python.org | |
-------------------------------------------------- | |
Page 2: |