XPath Tester
Prueba expresiones XPath contra documentos XML.
Acerca de esta herramienta
XPath es un lenguaje de consulta potente para navegar y extraer datos de documentos XML. Esta herramienta te permite probar expresiones XPath directamente en tu navegador sin necesidad de herramientas del lado del servidor ni configuraciones complejas de IDE. Ya sea que trabajes con archivos de configuración, fuentes de datos o respuestas API en formato XML, XPath Tester te ayuda a encontrar y validar los elementos exactos que necesitas rápidamente.
Para usar la herramienta, pega o escribe tu documento XML en el editor, luego escribe tu expresión XPath en el campo de consulta y ejecútala. La herramienta muestra inmediatamente todos los elementos coincidentes, resaltando exactamente lo que tu expresión selecciona. Puedes refinar tu consulta en tiempo real para navegar estructuras anidadas, filtrar por atributos o extraer contenido de texto específico.
Preguntas Frecuentes
Implementación de Código
from lxml import etree
xml_text = """<?xml version="1.0"?>
<bookstore>
<book category="cooking">
<title>Everyday Italian</title>
<price>30.00</price>
</book>
<book category="web">
<title>Learning XML</title>
<price>39.95</price>
</book>
</bookstore>"""
root = etree.fromstring(xml_text.encode())
# Basic XPath queries
titles = root.xpath("//book/title/text()")
print("All titles:", titles)
# Predicate filter
web_books = root.xpath("//book[@category='web']/title/text()")
print("Web books:", web_books)
# Aggregate function
prices = root.xpath("//price/text()")
total = sum(float(p) for p in prices)
print(f"Total: {total:.2f}")
# Namespace example
NS = {"ns": "http://www.example.com/ns"}
# root.xpath("//ns:book", namespaces=NS)Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.