这是我的xml文件:需要帮助使用查询类型xml
编写正确的xpath表达式<?xml version="1.0" encoding="UTF-8"?>
<CONTACTS>
<CONTACT>
<PDE-Identity>N65539</PDE-Identity>
<FirstName>Arun_niit</FirstName>
<LastName>Arun_niit</LastName>
<Facebook-ID/>
<EMAILS>
<EMail Domain="yahoo" Value="nura_e@yahoo.co.in"/>
</EMAILS>
</CONTACT>
<CONTACT>
<PDE-Identity>N65553</PDE-Identity>
<FirstName>GhorbelMahmoud</FirstName>
<LastName>Mahmoud Ghorbel</LastName>
<Facebook-ID/>
<EMAILS>
<EMail Domain="alcatel-lucent" Value="mahmoud.gbel@alcatel-lucent.com"/>
</EMAILS>
</CONTACT>
<CONTACT>
<PDE-Identity>N65560</PDE-Identity>
<FirstName>keyankarthik</FirstName>
<LastName>karthik keyan</LastName>
<Facebook-ID/>
<EMAILS>
<EMail Domain="yahoo" Value="kartse@yahoo.co.in"/>
</EMAILS>
</CONTACT>
<CONTACT>
<PDE-Identity>N65567</PDE-Identity>
<FirstName>Rangarajkarthik</FirstName>
<LastName>karthik Rangaraj</LastName>
<Facebook-ID/>
<EMAILS>
<EMail Domain="gmail" Value="kart2006@gmail.com"/>
<EMail Domain="yahoo" Value="karthikngaraj@yahoo.com"/>
</EMAILS>
</CONTACT>
<CONTACT>
<PDE-Identity>N65576</PDE-Identity>
<FirstName>ReddyAkky</FirstName>
<LastName>Akky Reddy</LastName>
<Facebook-ID/>
<EMAILS>
<EMail Domain="gmail" Value="akkddych@gmail.com"/>
</EMAILS>
</CONTACT>
<CONTACT>
<PDE-Identity>N65597</PDE-Identity>
<FirstName>KumarVeera</FirstName>
<LastName>Veera_Kumar</LastName>
<Facebook-ID/>
<EMAILS>
<EMail Domain="yahoo" Value="KUMRg_81@yahoo.com"/>
</EMAILS>
</CONTACT>
</CONTACTS>
我的xul树:
<treechildren datasources="file://D:/xmlparserinxul/finalxmlonfriday.xml" ref="*" querytype="xml">
<template>
<query expr="CONTACT">
<assign var="?pde" expr="PDE-Identity"/>
<assign var="?fname" expr="FirstName"/>
<assign var="?lname" expr="LastName"/>
<assign var="?gmail" expr="EMAILS/EMail/@Domain='gmail'|EMail/@Value"/>
<assign var="?yahoo" expr="EMAILS/EMail/@Domain='yahoo'|EMail/@Value"/>
<assign var="?alcatel-lucent" expr="EMAILS/EMail/@Domain='alcatel-lucent'|EMail/@Value"/>
<assign var="?facebook" expr="URL"/>
<assign var="?id" expr="Facebook-ID"/>
</query>
<action>
<treeitem uri="?">
<treerow>
<treecell label="?pde"/>
<treecell label="?fname"/>
<treecell label="?lname"/>
<treecell label="?gmail"/>
<treecell label="?yahoo"/>
<treecell label="?alcatel-lucent"/>
<treecell label="?facebook" editable="false"/>
<treecell label="?id" editable="false"/>
</treerow>
</treeitem>
</action>
</template>
</treechildren>
</tree>
我无法根据域名编写正确的查询来讨论电子邮件值。有人请帮助我......我在这里编辑了上一个问题..
答案 0 :(得分:1)
通常的方法是使用XML模板并自动生成树内容,请参阅https://developer.mozilla.org/en/XUL/Template_Guide/XML_Templates和https://developer.mozilla.org/en/XUL/Template_Guide/XML_Assignments。在你的情况下它会像这样工作:
<treechildren datasources="file:///D:/FinalXMl.xml" ref="*" querytype="xml">
<template>
<query expr="CONTACT">
<assign var="?fname" expr="FirstName"/>
<assign var="?lname" expr="LastName"/>
<assign var="?gmail" expr="EMAILS/EMail[Type='gmail']/Value"/>
<assign var="?yahoo" expr="EMAILS/EMail[Type='yahoo']/Value"/>
<assign var="?facebook" expr="Facebook-ID"/>
</query>
<action>
<treeitem uri="?">
<treerow>
<treecell label="?fname"/>
<treecell label="?lname"/>
<treecell label="?gmail"/>
<treecell label="?yahoo"/>
<treecell label=""/>
<treecell label="?facebook"/>
</treerow>
</treeitem>
</action>
</template>
</treechildren>
请注意,如果您可以更改XML格式,这将更容易(<assign>
标记不必要)。如果将所有数据放入<CONTACT>
标记的属性中,则可以在不明确赋值的情况下访问它。
您似乎希望最终实现树的动态过滤,这应该通过动态更改expr
标记的<query>
属性来实现。您可以使用任何XPath表达式,例如expr="CONTACT[FirstName='Bob']"
只会选择FirstName
子级值为Bob
的联系人。