,我有以下格式的XML整個的XDocument:排序基於子節點
<?xml version="1.0" encoding="utf-8"?>
<contactGrp name="People">
<contactGrp name="Developers">
<customer name="Mike" ></customer>
<customer name="Brad" ></customer>
<customer name="Smith" ></customer>
</contactGrp>
<contactGrp name="QA">
<customer name="John" ></customer>
<customer name="abi" ></customer>
</contactGrp>
</contactGrp>
我想排序基於他們的名字客戶名單,並在下面的格式返回文檔:
<?xml version="1.0" encoding="utf-8"?>
<contactGrp name="People">
<contactGrp name="Developers">
<customer name="Brad" ></customer>
<customer name="Mike" ></customer>
<customer name="Smith" ></customer>
</contactGrp>
<contactGrp name="QA">
<customer name="abi" ></customer>
<customer name="John" ></customer>
</contactGrp>
</contactGrp>
我正在使用c#和當前xmldocument。
謝謝
我很混亂,因爲'xpath'標籤...如果你想選擇一個節點集,那麼XPath可能有正確的技術。如果您想正確排序節點集,則需要XPath引擎主機語言。如果要轉換XML樹,標準資源是XSLT。 – 2011-02-27 21:31:26
我知道,我似乎無法解決我的問題。 – vondip 2011-02-27 21:38:09
好問題,+1。查看我的答案,瞭解適用於'contactGrp'元素的任何級別嵌套的完整,簡短且容易的XSLT解決方案。 :) – 2011-02-27 23:48:18