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 wave | |
with wave.open('example.wav', 'rb') as wav_file: | |
print(f'Channels: {wav_file.getnchannels()}') | |
print(f'Sample width: {wav_file.getsampwidth()} bytes') | |
print(f'Frame rate: {wav_file.getframerate()} Hz') | |
print(f'Number of frames: {wav_file.getnframes()}') | |
print(f'Parameters: {wav_file.getparams()}') | |
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
fetch('data.xml') | |
.then(response => response.text()) | |
.then(str => new window.DOMParser().parseFromString(str, "text/xml")) | |
.then(xml => console.log(xml.getElementsByTagName("item")[0].textContent)); |
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
const xmlString = "<root><item>Hello</item></root>"; | |
const parser = new DOMParser(); | |
const xmlDoc = parser.parseFromString(xmlString, "text/xml"); | |
console.log(xmlDoc.getElementsByTagName("item")[0].textContent); | |
// Output: Hello |
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.SAXParser; | |
import javax.xml.parsers.SAXParserFactory; | |
import org.xml.sax.*; | |
import org.xml.sax.helpers.DefaultHandler; | |
import java.io.*; | |
class SAXHandler extends DefaultHandler { | |
public void startElement(String uri, String localName, String qName, Attributes attributes) { | |
System.out.println("Element: " + qName); | |
} |
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 XMLParser { | |
public static void main(String[] args) throws Exception { | |
File file = new File("data.xml"); | |
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); | |
DocumentBuilder builder = factory.newDocumentBuilder(); | |
Document doc = builder.parse(file); |
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 bs4 import BeautifulSoup | |
xml_data = "<root><item>Data</item></root>" | |
soup = BeautifulSoup(xml_data, "xml") | |
print(soup.item.text) # Output: Data |
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 lxml import etree | |
xml_data = "<root><element key='value'>Text</element></root>" | |
tree = etree.fromstring(xml_data) | |
print(tree.xpath('//element/@key')) # Output: ['value'] |
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 | |
xml_data = """ | |
<data> | |
<item> | |
<name>Book</name> | |
<price>10.99</price> | |
</item> | |
</data> | |
""" |
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 id="1"><title>XML Guide</title><price>29.99</price></book></books>`; | |
let parser = new DOMParser(); | |
let xmlDoc = parser.parseFromString(xmlString, "text/xml"); | |
let book = xmlDoc.getElementsByTagName("book")[0]; | |
book.getElementsByTagName("price")[0].childNodes[0].nodeValue = "24.99"; | |
let serializer = new XMLSerializer(); | |
let updatedXML = serializer.serializeToString(xmlDoc); | |
console.log(updatedXML); |
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.*; | |
import javax.xml.transform.*; | |
import javax.xml.transform.dom.DOMSource; | |
import javax.xml.transform.stream.StreamResult; | |
public class EditXML { | |
public static void main(String[] args) throws Exception { | |
File inputFile = new File("books.xml"); |
NewerOlder