2011-11-10 108 views
0

我需要解析XMind包中的content.xml文件。
文件看起來像這樣無法使用XPath讀取xml

<xmap-content xmlns="urn:xmind:xmap:xmlns:content:2.0" xmlns:fo="http://www.w3.org/1999/XSL /Format" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink" version="2.0"> 

    <sheet id="sdfasdfsdf"> 
     <title> Sheet1 </title> 
    </sheet> 

    <sheet id="fgasdfgasr"> 
     <title> Sheet2 </title> 
    </sheet> 
<xmap-content> 

我需要把所有表的標題列表。

我使用XPathExpression expr = navigator.Compile("//sheet");
但我猜它不工作
做什麼。任何建議或代碼都可以。
thnx提前。

+0

如何讓''值一旦我有'XPathNavigator'對於給定'<sheet>'......以及我正在迭代使用'XPathNodeIterator iterator = navigator.Select(「// xm:sheet」,manager);' – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/939430/">j4m4l</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">2<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"> <p>你的XML定義了默認命名空間:<code class="prettyprint-override">urn:xmind:xmap:xmlns:content:2.0</code>。所以,你需要將它傳遞給前綴的XML引擎,然後使用表達式:</p> <pre><code class="prettyprint-override">//ns:sheet </code></pre> <p>或另一種方式:</p> <pre><code class="prettyprint-override">//*[local-name() = 'sheet'] </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/8077142">來源</a> </span> </p> <p class="text-secondary col-lg-6"> <span class="float-right date"> <span>2011-11-10 09:09:23</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">我如何將默認命名空間傳遞給xml引擎。使用XPath – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/939430/">j4m4l</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">+0</span></div> <div class="col-lg-11"> <p class="commenttext">@ j4m4l,使用'XmlNamespaceManager':http://msdn.microsoft.com/en-us/library/tywd160x.aspx – <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">@ j4m4l,我已經更新了我的答案。 – <span class="text-secondary"> <small> <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>嘗試</p> <pre><code class="prettyprint-override">XPathExpression expr = navigator.Compile("xmap-content/sheet"); </code></pre> <p>編輯:</p> <pre><code class="prettyprint-override">string st = @"<xmap-content xmlns=""urn:xmind:xmap:xmlns:content:2.0"" xmlns:fo=""http://www.w3.org/1999/XSL /Format"" xmlns:svg=""http://www.w3.org/2000/svg"" xmlns:xhtml=""http://www.w3.org/1999/xhtml"" xmlns:xlink=""http://www.w3.org/1999/xlink"" version=""2.0""> <sheet id=""sdfasdfsdf""> <title> Sheet1 </title> </sheet> <sheet id=""fgasdfgasr""> <title> Sheet2 </title> </sheet> </xmap-content>"; XmlDocument document = new XmlDocument(); document.LoadXml(st); XmlNamespaceManager manager = new XmlNamespaceManager(document.NameTable); manager.AddNamespace("xm", "urn:xmind:xmap:xmlns:content:2.0"); var titles = document.SelectNodes("//xm:sheet/xm:title", manager); </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/8077058">來源</a> </span> </p> <p class="text-secondary col-lg-6"> <span class="float-right date"> <span>2011-11-10 09:02:03</span> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/2558060/">Damith</a></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">那不行,我猜它的命名空間問題 – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/939430/">j4m4l</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">+0</span></div> <div class="col-lg-11"> <p class="commenttext">ok,試着用命名空間正如kirils所說 – <span class="text-secondary"> <small> <a rel="noopener" target="_blank" href="https://stackoverflow.com/users/2558060/">Damith</a></span> <span></span> </small> </span> </p> </div> </div> </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-zkoqsxsu-bnn.html" target="_blank" title="使用XPath讀取XML"> 使用XPath讀取XML </a> </li> <li> 2. <a href="http://hk.uwenku.com/question/p-faegvaft-uw.html" target="_blank" title="使用xpath查詢讀取xml java"> 使用xpath查詢讀取xml java </a> </li> <li> 3. <a href="http://hk.uwenku.com/question/p-aluiiuep-bnh.html" target="_blank" title="使用XPATH讀取XML PHP DOM"> 使用XPATH讀取XML PHP DOM </a> </li> <li> 4. <a href="http://hk.uwenku.com/question/p-qbkjmtzp-kg.html" target="_blank" title="VB - 使用XPath讀取XML的問題"> VB - 使用XPath讀取XML的問題 </a> </li> <li> 5. <a href="http://hk.uwenku.com/question/p-feynrhjs-bad.html" target="_blank" title="使用XPath讀取大型XML文件"> 使用XPath讀取大型XML文件 </a> </li> <li> 6. <a href="http://hk.uwenku.com/question/p-pyonoozz-hu.html" target="_blank" title="無法使用C#和XmlDocument讀取XML"> 無法使用C#和XmlDocument讀取XML </a> </li> <li> 7. <a href="http://hk.uwenku.com/question/p-pfncbfzr-rq.html" target="_blank" title="無法使用jQuery讀取XML文件"> 無法使用jQuery讀取XML文件 </a> </li> <li> 8. <a href="http://hk.uwenku.com/question/p-fzjpsxah-hv.html" target="_blank" title="無法使用JAXB讀取XML文件?"> 無法使用JAXB讀取XML文件? </a> </li> <li> 9. <a href="http://hk.uwenku.com/question/p-tsbnrfnk-wd.html" target="_blank" title="讀個XML使用XPath"> 讀個XML使用XPath </a> </li> <li> 10. <a href="http://hk.uwenku.com/question/p-wvatbjon-eu.html" target="_blank" title="無法使用Xpath解析XML"> 無法使用Xpath解析XML </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-nnpaxbaz-qe.html" target="_blank" title="使用JaxB無法讀取讀取xml屬性"> 使用JaxB無法讀取讀取xml屬性 </a> </li> <li> 12. <a href="http://hk.uwenku.com/question/p-xlequidx-bew.html" target="_blank" title="無法讀取XML數據"> 無法讀取XML數據 </a> </li> <li> 13. <a href="http://hk.uwenku.com/question/p-heinvnnz-ow.html" target="_blank" title="無法讀取XML文件"> 無法讀取XML文件 </a> </li> <li> 14. <a href="http://hk.uwenku.com/question/p-kwpetzwl-bhh.html" target="_blank" title="xml無法讀取URL"> xml無法讀取URL </a> </li> <li> 15. <a href="http://hk.uwenku.com/question/p-qkahobgo-bhn.html" target="_blank" title="無法正確讀取XML"> 無法正確讀取XML </a> </li> <li> 16. <a href="http://hk.uwenku.com/question/p-qrvvofqc-ov.html" target="_blank" title="無法讀取XML文件"> 無法讀取XML文件 </a> </li> <li> 17. <a href="http://hk.uwenku.com/question/p-musbhemr-ox.html" target="_blank" title="用XPATH讀取棘手的XML"> 用XPATH讀取棘手的XML </a> </li> <li> 18. <a href="http://hk.uwenku.com/question/p-rwtldtqi-wn.html" target="_blank" title="將XML導入到數據集或使用XPath讀取XML?"> 將XML導入到數據集或使用XPath讀取XML? </a> </li> <li> 19. <a href="http://hk.uwenku.com/question/p-zbzqwgip-bhn.html" target="_blank" title="XPATH問題。無法讀取部分html"> XPATH問題。無法讀取部分html </a> </li> <li> 20. <a href="http://hk.uwenku.com/question/p-zixerftm-zg.html" target="_blank" title="獲取從XML使用XPath"> 獲取從XML使用XPath </a> </li> <li> 21. <a href="http://hk.uwenku.com/question/p-yhfxqpsq-bbc.html" target="_blank" title="無法讀取使用LINQ to XML的XML註釋"> 無法讀取使用LINQ to XML的XML註釋 </a> </li> <li> 22. <a href="http://hk.uwenku.com/question/p-dclxvqva-bhd.html" target="_blank" title="無法讀取rss XML,使用簡單的XML和翻新"> 無法讀取rss XML,使用簡單的XML和翻新 </a> </li> <li> 23. <a href="http://hk.uwenku.com/question/p-wcvvlbnh-nk.html" target="_blank" title="無法讀取XML文件用C#"> 無法讀取XML文件用C# </a> </li> <li> 24. <a href="http://hk.uwenku.com/question/p-rrblzetj-op.html" target="_blank" title="無法使用XPath"> 無法使用XPath </a> </li> <li> 25. <a href="http://hk.uwenku.com/question/p-efnehvnk-yk.html" target="_blank" title="無法使用XPath"> 無法使用XPath </a> </li> <li> 26. <a href="http://hk.uwenku.com/question/p-yqywmprt-bhz.html" target="_blank" title="無法使用XPATH"> 無法使用XPATH </a> </li> <li> 27. <a href="http://hk.uwenku.com/question/p-slubnfgk-ta.html" target="_blank" title="無法使用XPath"> 無法使用XPath </a> </li> <li> 28. <a href="http://hk.uwenku.com/question/p-nnfrdhvm-bnm.html" target="_blank" title="C#xml讀/寫/ xpath不使用XmlDocument"> C#xml讀/寫/ xpath不使用XmlDocument </a> </li> <li> 29. <a href="http://hk.uwenku.com/question/p-yymiprhl-hq.html" target="_blank" title="無法使用' - '使用PHP中的SimpleXMLElement讀取XML標籤"> 無法使用' - '使用PHP中的SimpleXMLElement讀取XML標籤 </a> </li> <li> 30. <a href="http://hk.uwenku.com/question/p-fzcxpaaf-beo.html" target="_blank" title="無法使用xpath獲取span標記"> 無法使用xpath獲取span標記 </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-vyjyhjfq-bhe.html" target="_blank" title="Select2 templateResult數據沒有可供引用的元素"> Select2 templateResult數據沒有可供引用的元素 </a> </li> <li class="side_article_list_item"> 2. <a href="http://hk.uwenku.com/question/p-wdyiixcv-bhu.html" target="_blank" title="建模Azure Cosmos DB"> 建模Azure Cosmos DB </a> </li> <li class="side_article_list_item"> 3. <a href="http://hk.uwenku.com/question/p-gmfjrbst-bkk.html" target="_blank" title="從一個數據框中創建一個以一列值爲參考的數組"> 從一個數據框中創建一個以一列值爲參考的數組 </a> </li> <li class="side_article_list_item"> 4. <a href="http://hk.uwenku.com/question/p-xfvbmagw-bkb.html" target="_blank" title="CRM 2016升級服務 - 案例 - 環境"> CRM 2016升級服務 - 案例 - 環境 </a> </li> <li class="side_article_list_item"> 5. <a href="http://hk.uwenku.com/question/p-guqohxxm-bkx.html" target="_blank" title="圖書館是建設應用程序必不可少的?"> 圖書館是建設應用程序必不可少的? </a> </li> <li class="side_article_list_item"> 6. <a href="http://hk.uwenku.com/question/p-cjrbhwad-zv.html" target="_blank" title="角5類型錯誤:this.tipp.isPersistent不是一個函數"> 角5類型錯誤:this.tipp.isPersistent不是一個函數 </a> </li> <li class="side_article_list_item"> 7. <a href="http://hk.uwenku.com/question/p-ywlbpvus-bak.html" target="_blank" title="Unique_ptr C++用法"> Unique_ptr C++用法 </a> </li> <li class="side_article_list_item"> 8. <a href="http://hk.uwenku.com/question/p-gjurezuu-bcq.html" target="_blank" title="如何使用Java 8和StringJoiner連接來自列表的兩個字段?"> 如何使用Java 8和StringJoiner連接來自列表的兩個字段? </a> </li> <li class="side_article_list_item"> 9. <a href="http://hk.uwenku.com/question/p-htscpszy-bca.html" target="_blank" title="如何刷新改進2/rxJava中的ACCESS-TOKEN"> 如何刷新改進2/rxJava中的ACCESS-TOKEN </a> </li> <li class="side_article_list_item"> 10. <a href="http://hk.uwenku.com/question/p-etgmkhto-bbu.html" target="_blank" title="VBA搜索表格排除空白單元格"> VBA搜索表格排除空白單元格 </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-zkoqsxsu-bnn.html" target="_blank" title="使用XPath讀取XML"> 使用XPath讀取XML </a> </li> <li class="side_article_list_item"> 2. <a href="http://hk.uwenku.com/question/p-faegvaft-uw.html" target="_blank" title="使用xpath查詢讀取xml java"> 使用xpath查詢讀取xml java </a> </li> <li class="side_article_list_item"> 3. <a href="http://hk.uwenku.com/question/p-aluiiuep-bnh.html" target="_blank" title="使用XPATH讀取XML PHP DOM"> 使用XPATH讀取XML PHP DOM </a> </li> <li class="side_article_list_item"> 4. <a href="http://hk.uwenku.com/question/p-qbkjmtzp-kg.html" target="_blank" title="VB - 使用XPath讀取XML的問題"> VB - 使用XPath讀取XML的問題 </a> </li> <li class="side_article_list_item"> 5. <a href="http://hk.uwenku.com/question/p-feynrhjs-bad.html" target="_blank" title="使用XPath讀取大型XML文件"> 使用XPath讀取大型XML文件 </a> </li> <li class="side_article_list_item"> 6. <a href="http://hk.uwenku.com/question/p-pyonoozz-hu.html" target="_blank" title="無法使用C#和XmlDocument讀取XML"> 無法使用C#和XmlDocument讀取XML </a> </li> <li class="side_article_list_item"> 7. <a href="http://hk.uwenku.com/question/p-pfncbfzr-rq.html" target="_blank" title="無法使用jQuery讀取XML文件"> 無法使用jQuery讀取XML文件 </a> </li> <li class="side_article_list_item"> 8. <a href="http://hk.uwenku.com/question/p-fzjpsxah-hv.html" target="_blank" title="無法使用JAXB讀取XML文件?"> 無法使用JAXB讀取XML文件? </a> </li> <li class="side_article_list_item"> 9. <a href="http://hk.uwenku.com/question/p-tsbnrfnk-wd.html" target="_blank" title="讀個XML使用XPath"> 讀個XML使用XPath </a> </li> <li class="side_article_list_item"> 10. <a href="http://hk.uwenku.com/question/p-wvatbjon-eu.html" target="_blank" title="無法使用Xpath解析XML"> 無法使用Xpath解析XML </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>