2012-06-20 184 views
3

具有以下XML示例文檔,我需要發佈一個XPath/XQuery表達式來獲取CD元素的每個子元素的元素名稱。使用XPath/XQuery獲取元素名稱

<CD> 
    <TITLE>Empire Burlesque</TITLE> 
    <ARTIST>Bob Dylan</ARTIST> 
    <COUNTRY>USA</COUNTRY> 
    <COMPANY>Columbia</COMPANY> 
    <PRICE>10.90</PRICE> 
    <YEAR>1985</YEAR> 
</CD> 

所以我需要查詢返回標題,藝術家,國家,國家,價格,年份,任何一個可以幫助嗎? 感謝

+0

您的術語與您的示例不符。 ''等是'<CD>'的子元素,而不是屬性。 – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/267781/">MattH</a></span> <span></span> </small> </span> </p> </div> </div> </div> </div> </div> </article> </div> <div class="answer-title"> <span class="text-logo margin-top-sm">A</span> <h2 class="title h4">回答</h2> </div> <div class="item-description text-md markdown-body margin-bottom-40 voidso"> <article class="board-top-1 padding-top-10"> <div class="post-col vote-info"> <span class="count">14<i class="fa fa-thumbs-up"></i></span> <i class="fa fa-check fa-2x"></i> </div> <div class="post-offset"> <div class="answer fmt"> <pre><code class="prettyprint-override">/CD/*/name() </code></pre> <p>(填充,因爲StackOverflow上不喜歡簡答題)</p> </div> <div class="post-info"> <div class="post-meta row"> <p class="text-secondary col-lg-6"> <span class="source"> <a rel="noopener" target="_blank" href="https://stackoverflow.com/q/11122559">來源</a> </span> </p> <p class="text-secondary col-lg-6"> <span class="float-right date"> <span>2012-06-20 15:09:34</span> </p> <p class="col-12"></p> <p class="col-12"></p></div> </div> <!-- comments --> <div class="comments"> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">如果我們想要返回CD,該怎麼辦? just name()? ./name()返回空白...試圖獲取根節點的名稱 – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/2415973/">tenwest</a></span> <span></span> </small> </span> </p> </div> </div> </div> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+1</span></div> <div class="col-lg-11"> <p class="commenttext">name(/ *) - 最外層的元素不是XPath數據模型中的「根節點」;它有一個父節點,它在XPath 1.0中稱爲根節點,或者在XPath 2.0中稱爲文檔節點。 – <span class="text-secondary"> <small> <span></span> </small> </span> </p> </div> </div> </div> <div itemprop="comment" class="post-comment"> <div class="row"> <div class="col-lg-1"><span class="text-secondary">+0</span></div> <div class="col-lg-11"> <p class="commenttext">我明白了,有道理。謝謝,這對我有用 – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/2415973/">tenwest</a></span> <span></span> </small> </span> </p> </div> </div> </div> </div> </div> </article> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="1038284119" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <article class="board-top-1 padding-top-10"> <div class="post-col vote-info"> <span class="count">0<i class="fa fa-thumbs-up"></i></span> </div> <div class="post-offset"> <div class="answer fmt"> <p>嘗試<code class="prettyprint-override">/\*/name()</code><br> 例如對於Oracle使用</p> <pre><code class="prettyprint-override">XMLCast(XMLQuery('/*/name()' PASSING db_some_field_name RETURNING CONTENT) AS VARCHAR2(4000)) </code></pre> </div> <div class="post-info"> <div class="post-meta row"> <p class="text-secondary col-lg-6"> <span class="source"> <a rel="noopener" target="_blank" href="https://stackoverflow.com/q/36630042">來源</a> </span> </p> <p class="text-secondary col-lg-6"> <span class="float-right date"> <span>2016-04-14 17:29:19</span> </p> <p class="col-12"></p> <p class="col-12"></p></div> </div> </div> </article> </div> <div class="clearfix"> </div> <div class="relative-box"> <div class="relative">相關問題</div> <ul class="relative_list"> <li> 1. <a href="http://hk.uwenku.com/question/p-wkutmwox-ma.html" target="_blank" title="使用jQuery獲取DOM元素名稱"> 使用jQuery獲取DOM元素名稱 </a> </li> <li> 2. <a href="http://hk.uwenku.com/question/p-xbfevebn-pw.html" target="_blank" title="獲取元素名稱"> 獲取元素名稱 </a> </li> <li> 3. <a href="http://hk.uwenku.com/question/p-makqkkxi-ro.html" target="_blank" title="Javascript - 從元素名稱獲取元素?"> Javascript - 從元素名稱獲取元素? </a> </li> <li> 4. <a href="http://hk.uwenku.com/question/p-ykqrfhfx-cn.html" target="_blank" title="BCEL - 獲取類名稱,元素名稱和方法名稱"> BCEL - 獲取類名稱,元素名稱和方法名稱 </a> </li> <li> 5. <a href="http://hk.uwenku.com/question/p-tonujczv-k.html" target="_blank" title="按名稱獲取元素字符串"> 按名稱獲取元素字符串 </a> </li> <li> 6. <a href="http://hk.uwenku.com/question/p-pwdnittu-o.html" target="_blank" title="獲取元素ID由名稱"> 獲取元素ID由名稱 </a> </li> <li> 7. <a href="http://hk.uwenku.com/question/p-qyfdxgrn-yw.html" target="_blank" title="按名稱獲取XML元素"> 按名稱獲取XML元素 </a> </li> <li> 8. <a href="http://hk.uwenku.com/question/p-xrakznby-vb.html" target="_blank" title="從JSON獲取元素屬性名稱"> 從JSON獲取元素屬性名稱 </a> </li> <li> 9. <a href="http://hk.uwenku.com/question/p-uuzsstke-bdr.html" target="_blank" title="獲取元素名稱與GSON"> 獲取元素名稱與GSON </a> </li> <li> 10. <a href="http://hk.uwenku.com/question/p-tzorpovb-bdz.html" target="_blank" title="獲取C#中Focused元素的名稱#"> 獲取C#中Focused元素的名稱# </a> </li> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-6208739752673518" data-ad-slot="4606349252"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <li> 11. <a href="http://hk.uwenku.com/question/p-hpkorvcf-bgy.html" target="_blank" title="的元素名稱獲取XML值"> 的元素名稱獲取XML值 </a> </li> <li> 12. <a href="http://hk.uwenku.com/question/p-rccrevnm-cm.html" target="_blank" title="在XPath中獲取父元素名稱"> 在XPath中獲取父元素名稱 </a> </li> <li> 13. <a href="http://hk.uwenku.com/question/p-stxrzxfb-pp.html" target="_blank" title="按屬性名稱獲取HTML元素"> 按屬性名稱獲取HTML元素 </a> </li> <li> 14. <a href="http://hk.uwenku.com/question/p-mwmnoeew-dd.html" target="_blank" title="獲取唯一元素名稱的XPath"> 獲取唯一元素名稱的XPath </a> </li> <li> 15. <a href="http://hk.uwenku.com/question/p-rutdqjcb-rr.html" target="_blank" title="通過名稱/編號獲取元素"> 通過名稱/編號獲取元素 </a> </li> <li> 16. <a href="http://hk.uwenku.com/question/p-chrisomk-ze.html" target="_blank" title="獲取子元素的名稱"> 獲取子元素的名稱 </a> </li> <li> 17. <a href="http://hk.uwenku.com/question/p-njgehmre-bgg.html" target="_blank" title="Javascript按名稱獲取子元素"> Javascript按名稱獲取子元素 </a> </li> <li> 18. <a href="http://hk.uwenku.com/question/p-znobcdxw-bgt.html" target="_blank" title="在rapply中獲取元素名稱"> 在rapply中獲取元素名稱 </a> </li> <li> 19. <a href="http://hk.uwenku.com/question/p-yysrduuy-bgy.html" target="_blank" title="在DocumentEvent中獲取元素名稱"> 在DocumentEvent中獲取元素名稱 </a> </li> <li> 20. <a href="http://hk.uwenku.com/question/p-chmqugnl-bam.html" target="_blank" title="如何獲取具有以下名稱的元素:名稱中?"> 如何獲取具有以下名稱的元素:名稱中? </a> </li> <li> 21. <a href="http://hk.uwenku.com/question/p-rangmxmn-qa.html" target="_blank" title="在ExpandableListView中獲取子元素的名稱或名稱"> 在ExpandableListView中獲取子元素的名稱或名稱 </a> </li> <li> 22. <a href="http://hk.uwenku.com/question/p-gbtbocwr-ex.html" target="_blank" title="如何通過給定的元素名稱獲取pvob名稱?"> 如何通過給定的元素名稱獲取pvob名稱? </a> </li> <li> 23. <a href="http://hk.uwenku.com/question/p-seyduqbu-q.html" target="_blank" title="如何通過名稱使用jquery獲取元素?"> 如何通過名稱使用jquery獲取元素? </a> </li> <li> 24. <a href="http://hk.uwenku.com/question/p-tngtxyzc-oq.html" target="_blank" title="獲取元素的名稱/使用XML /的XPath/PHP"> 獲取元素的名稱/使用XML /的XPath/PHP </a> </li> <li> 25. <a href="http://hk.uwenku.com/question/p-ckqrgwyc-xq.html" target="_blank" title="如何使用JavaScript獲取元素/組件名稱?"> 如何使用JavaScript獲取元素/組件名稱? </a> </li> <li> 26. <a href="http://hk.uwenku.com/question/p-tualvmsc-su.html" target="_blank" title="獲取XML元素的名稱,並使用SQL XPath查詢"> 獲取XML元素的名稱,並使用SQL XPath查詢 </a> </li> <li> 27. <a href="http://hk.uwenku.com/question/p-bydybvij-bu.html" target="_blank" title="JQuery使用名稱獲取元素AND ID"> JQuery使用名稱獲取元素AND ID </a> </li> <li> 28. <a href="http://hk.uwenku.com/question/p-parftkkz-kt.html" target="_blank" title="如何使用xsl獲取元素名稱及其值?"> 如何使用xsl獲取元素名稱及其值? </a> </li> <li> 29. <a href="http://hk.uwenku.com/question/p-vytiotiq-bdr.html" target="_blank" title="如何使用LINQ在XML中按名稱獲取元素"> 如何使用LINQ在XML中按名稱獲取元素 </a> </li> <li> 30. <a href="http://hk.uwenku.com/question/p-qnkvhazr-beh.html" target="_blank" title="使用元素名稱獲取屬性ID"> 使用元素名稱獲取屬性ID </a> </li> </ul> </div> <div> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-6208739752673518" data-ad-slot="1575177025"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="padding-top-10"></div> </div> </div> <script type="text/javascript" src="http://img.uwenku.com/uwenku/script/side.js?t=1644592048261"></script> <script type="text/javascript" src="http://img.uwenku.com/uwenku/plugin/highlight/highlight.pack.js"></script> <link href="http://img.uwenku.com/uwenku/plugin/highlight/styles/docco.css" media="screen" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $('pre').each(function(i, e) { hljs.highlightBlock(e, "<span class='indent'> </span>", false) }); </script> <div class="col-lg-3 col-md-4 col-sm-5"> <div id="rightTop"> <div class="row"> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-6208739752673518" data-ad-slot="5415218910" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> <div class="row sidebar panel panel-default"> <div class="panel-heading font-bold"> 最新問題 </div> <div class="m-b-sm m-t-sm clearfix"> <ul class="side_article_list"> <li class="side_article_list_item"> 1. <a href="http://hk.uwenku.com/question/p-biqyvgby-bmt.html" target="_blank" title="openapi v3響應正文中的多行示例"> openapi v3響應正文中的多行示例 </a> </li> <li class="side_article_list_item"> 2. <a href="http://hk.uwenku.com/question/p-oepdilmp-bmn.html" target="_blank" title="Python 3.6.3 urlopen從URI中刪除服務器名稱以存儲在遠程服務器上的html文件"> Python 3.6.3 urlopen從URI中刪除服務器名稱以存儲在遠程服務器上的html文件 </a> </li> <li class="side_article_list_item"> 3. <a href="http://hk.uwenku.com/question/p-kdthjqxu-bnw.html" target="_blank" title="8位內聯彙編大小不匹配旋轉"> 8位內聯彙編大小不匹配旋轉 </a> </li> <li class="side_article_list_item"> 4. <a href="http://hk.uwenku.com/question/p-recklsrc-bnq.html" target="_blank" title="將字符串數組從WWW轉換爲Unity3d中的類列表"> 將字符串數組從WWW轉換爲Unity3d中的類列表 </a> </li> <li class="side_article_list_item"> 5. <a href="http://hk.uwenku.com/question/p-heqakphf-bnh.html" target="_blank" title="按鈕上的顏色隨時變化"> 按鈕上的顏色隨時變化 </a> </li> <li class="side_article_list_item"> 6. <a href="http://hk.uwenku.com/question/p-tjfkzchb-bcw.html" target="_blank" title="創建簡單的P2P網絡"> 創建簡單的P2P網絡 </a> </li> <li class="side_article_list_item"> 7. <a href="http://hk.uwenku.com/question/p-psejxepn-bdc.html" target="_blank" title="添加和更改網頁中的動態內容"> 添加和更改網頁中的動態內容 </a> </li> <li class="side_article_list_item"> 8. <a href="http://hk.uwenku.com/question/p-wkacljdr-bdn.html" target="_blank" title="字典分配"> 字典分配 </a> </li> <li class="side_article_list_item"> 9. <a href="http://hk.uwenku.com/question/p-ewahdfbq-bgy.html" target="_blank" title="基於彈簧配置文件的彈簧引導應用程序屬性"> 基於彈簧配置文件的彈簧引導應用程序屬性 </a> </li> <li class="side_article_list_item"> 10. <a href="http://hk.uwenku.com/question/p-chgwggio-bhu.html" target="_blank" title="NodeJs - 異步/待機異步/等待"> NodeJs - 異步/待機異步/等待 </a> </li> </ul> </div> </div> </div> <p class="article-nav-bar"></p> <div class="row sidebar article-nav"> <div class="row box_white visible-sm visible-md visible-lg margin-zero"> <div class="top"> <h3 class="title"><i class="glyphicon glyphicon-th-list"></i> 相關問題</h3> </div> <div class="article-relative-content"> <ul class="side_article_list"> <li class="side_article_list_item"> 1. <a href="http://hk.uwenku.com/question/p-wkutmwox-ma.html" target="_blank" title="使用jQuery獲取DOM元素名稱"> 使用jQuery獲取DOM元素名稱 </a> </li> <li class="side_article_list_item"> 2. <a href="http://hk.uwenku.com/question/p-xbfevebn-pw.html" target="_blank" title="獲取元素名稱"> 獲取元素名稱 </a> </li> <li class="side_article_list_item"> 3. <a href="http://hk.uwenku.com/question/p-makqkkxi-ro.html" target="_blank" title="Javascript - 從元素名稱獲取元素?"> Javascript - 從元素名稱獲取元素? </a> </li> <li class="side_article_list_item"> 4. <a href="http://hk.uwenku.com/question/p-ykqrfhfx-cn.html" target="_blank" title="BCEL - 獲取類名稱,元素名稱和方法名稱"> BCEL - 獲取類名稱,元素名稱和方法名稱 </a> </li> <li class="side_article_list_item"> 5. <a href="http://hk.uwenku.com/question/p-tonujczv-k.html" target="_blank" title="按名稱獲取元素字符串"> 按名稱獲取元素字符串 </a> </li> <li class="side_article_list_item"> 6. <a href="http://hk.uwenku.com/question/p-pwdnittu-o.html" target="_blank" title="獲取元素ID由名稱"> 獲取元素ID由名稱 </a> </li> <li class="side_article_list_item"> 7. <a href="http://hk.uwenku.com/question/p-qyfdxgrn-yw.html" target="_blank" title="按名稱獲取XML元素"> 按名稱獲取XML元素 </a> </li> <li class="side_article_list_item"> 8. <a href="http://hk.uwenku.com/question/p-xrakznby-vb.html" target="_blank" title="從JSON獲取元素屬性名稱"> 從JSON獲取元素屬性名稱 </a> </li> <li class="side_article_list_item"> 9. <a href="http://hk.uwenku.com/question/p-uuzsstke-bdr.html" target="_blank" title="獲取元素名稱與GSON"> 獲取元素名稱與GSON </a> </li> <li class="side_article_list_item"> 10. <a href="http://hk.uwenku.com/question/p-tzorpovb-bdz.html" target="_blank" title="獲取C#中Focused元素的名稱#"> 獲取C#中Focused元素的名稱# </a> </li> </ul> </div> </div> </div> </div> </div> </div> </div><!-- wrap end--> <!-- footer --> <footer id="footer"> <div class="bg-simple lt"> <div class="container"> <div class="row padder-v m-t"> <div class="col-xs-8"> <ul class="list-inline"> <li><a href="http://hk.uwenku.com/contact">聯系我們</a></li> <li>© 2020 HK.UWENKU.COM</li> <li><a target="_blank" href="https://beian.miit.gov.cn/">沪ICP备13005482号-4</a></li> <li><script type="text/javascript" src="https://v1.cnzz.com/z_stat.php?id=1280101193&web_id=1280101193"></script></li> <li><a href="http://www.uwenku.com/" target="_blank" title="优文库">简体中文</a></li> <li><a href="http://hk.uwenku.com/" target="_blank" title="優文庫">繁體中文</a></li> <li><a href="http://ru.uwenku.com/" target="_blank" title="поле вопросов и ответов">Русский</a></li> <li><a href="http://de.uwenku.com/" target="_blank" title="Frage - und - antwort - Park">Deutsch</a></li> <li><a href="http://es.uwenku.com/" target="_blank" title="Preguntas y respuestas">Español</a></li> <li><a href="http://hi.uwenku.com/" target="_blank" title="कार्यक्रम प्रश्न और उत्तर पार्क">हिन्दी</a></li> <li><a href="http://it.uwenku.com/" target="_blank" title="IL Programma di chiedere Park">Italiano</a></li> <li><a href="http://ja.uwenku.com/" target="_blank" title="プログラム問答園区">日本語</a></li> <li><a href="http://ko.uwenku.com/" target="_blank" title="프로그램 문답 단지">한국어</a></li> <li><a href="http://pl.uwenku.com/" target="_blank" title="program o park">Polski</a></li> <li><a href="http://tr.uwenku.com/" target="_blank" title="Program soru ve cevap parkı">Türkçe</a></li> <li><a href="http://vi.uwenku.com/" target="_blank" title="Đáp ứng viên">Tiếng Việt</a></li> <li><a href="http://fr.uwenku.com/" target="_blank" title="Programme interrogation Park">Française</a></li> </ul> </div> </div> </div> </div> </div> </footer> <!-- / footer --> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?f78a970f17b19a79fc477a3378096f29"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>