문제

Background: I'm coming from C#-land, so I'm looking for something like being able to handle nodes and values by selecting via Xpath.

Here's my code, so far:

import urllib
import sys
from xml.parsers import expat

url = 'http://SomeWebService.SomeDomain.com'
u = urllib.urlopen(url)

Parser = expat.ParserCreate()
data = u.read()
try:
    Parser.Parse(data)
except:
    print "ERROR: Can't parse the XML"
    sys.exit(0)

What standard lib should I be using to deal with DOM elements as objects along with their attributes as one could in C#?

I'm looking for something like NodeList nodes = Parser.SelectNodes("Xpath")

도움이 되었습니까?

해결책

I think you would have more luck if you tried using one of the xml.dom packages, or xml.etree.ElementTree. ElementTree has some limited xpath support, so if that's what you're used to, it might be the best choice.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top