Tôi có tài liệu xml có phần tử gốc, hai phần tử con, 'chẩn đoán' và 'kết quả'. Phần tử 'results' sau đó có một số phần tử tùy ý với tên 'result'C# XmlDocument SelectNodes
Khi điều này được tải vào XmlDocument, rất dễ điều hướng cấu trúc và thấy rằng đây chính xác là cách hoạt động của nó. Tôi có thể viết một hàm đệ quy để chọn ra tất cả các phần tử "kết quả". Các XmlDocument.SelectNodes ("//kết quả") tìm thấy một nút không có vấn đề.
Tuy nhiên, * XmlDocument.SelectNodes ("// results/result") không tìm thấy gì.
* XmlDocument.SelectNodes ("// result") không tìm thấy gì cả.
Tôi đã nói chuyện với một đồng nghiệp và anh ấy đã đau buồn khi sử dụng Xpath trong XmlDocument.SelectNodes. Bất kỳ ai khác đều gặp phải vấn đề này? Bất kỳ giải pháp?
XML FILE:
<?xml version="1.0" encoding="UTF-8"?>
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng" yahoo:count="10" yahoo:created="2009-08-07T10:19:59Z" yahoo:lang="en-US" yahoo:updated="2009-08-07T10:19:59Z" yahoo:uri="http://query.yahooapis.com/v1/yql?q=select+*+from+search.news+where+query%3D%22Tanzania%22">
<diagnostics>
<publiclyCallable>true</publiclyCallable>
<url execution-time="47"><![CDATA[http://boss.yahooapis.com/ysearch/news/v1/Tanzania?format=xml&start=0&count=10]]></url>
<user-time>49</user-time>
<service-time>47</service-time>
<build-version>2579</build-version>
</diagnostics>
<results>
<result xmlns="http://www.inktomi.com/">
<abstract>Kakungulu Cup winners SC Villa face Tanzania’s Simba SC this afternoon at the National stadium in Dar es salaam. “We had a very tiresome journey. The road was so bad and the road blocks were so many. However, we finally reached but the boys were so tired,” said Kato.</abstract>
<clickurl>http://lrd.yahooapis.com/_ylc=X3oDMTQ4cXAxcnRoBF9TAzIwMjMxNTI3MDIEYXBwaWQDb0pfTWdwbklrWW5CMWhTZnFUZEd5TkouTXNxZlNMQmkEY2xpZW50A2Jvc3MEc2VydmljZQNCT1NTBHNsawN0aXRsZQRzcmNwdmlkA21VVGlta2dlQXUzeEYuM0xGQkQzR1pUU1FIS0dORXA4cUk4QUJJX1U-/SIG=12vhpskdd/**http%3A//www.monitor.co.ug/artman/publish/sports/SC_Villa_face_Simba_in_Tanzania_89289.shtml</clickurl>
<date>2009/08/07</date>
<language>english</language>
<source>The Monitor</source>
<sourceurl>http://www.monitor.co.ug/</sourceurl>
<time>20:22:32</time>
<title>SC Villa face Simba in Tanzania</title>
<url>http://www.monitor.co.ug/artman/publish/sports/SC_Villa_face_Simba_in_Tanzania_89289.shtml</url>
</result>
XPATH
doc.SelectNodes ("Kết quả //") không tạo hit.
Bạn có một mẫu của xml có liên quan không? Có thể các phần tử "kết quả" của bạn thực sự nằm trong một không gian tên khác với các phần tử "kết quả" không? Có bất kỳ tiền tố đủ điều kiện nào trên các phần tử không? –