在 XUL 树中使用条件查询类型 xml 从多个属性值中选择单个属性值
这是我的 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="[email protected]"/>
</EMAILS>
</CONTACT>
<CONTACT>
<PDE-Identity>N65553</PDE-Identity>
<FirstName>GhorbelMahmoud</FirstName>
<LastName>Mahmoud Ghorbel</LastName>
<Facebook-ID/>
<EMAILS>
<EMail Domain="alcatel-lucent" Value="[email protected]"/>
</EMAILS>
</CONTACT>
<CONTACT>
<PDE-Identity>N65560</PDE-Identity>
<FirstName>keyankarthik</FirstName>
<LastName>karthik keyan</LastName>
<Facebook-ID/>
<EMAILS>
<EMail Domain="yahoo" Value="[email protected]"/>
</EMAILS>
</CONTACT>
<CONTACT>
<PDE-Identity>N65567</PDE-Identity>
<FirstName>Rangarajkarthik</FirstName>
<LastName>karthik Rangaraj</LastName>
<Facebook-ID/>
<EMAILS>
<EMail Domain="gmail" Value="[email protected]"/>
<EMail Domain="yahoo" Value="[email protected]"/>
</EMAILS>
</CONTACT>
<CONTACT>
<PDE-Identity>N65576</PDE-Identity>
<FirstName>ReddyAkky</FirstName>
<LastName>Akky Reddy</LastName>
<Facebook-ID/>
<EMAILS>
<EMail Domain="gmail" Value="[email protected]"/>
</EMAILS>
</CONTACT>
<CONTACT>
<PDE-Identity>N65597</PDE-Identity>
<FirstName>KumarVeera</FirstName>
<LastName>Veera_Kumar</LastName>
<Facebook-ID/>
<EMAILS>
<EMail Domain="yahoo" Value="[email protected]"/>
</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>
我无法编写正确的查询来根据域讨论电子邮件值。请有人帮助我...我已经在这里编辑了上一个问题..
This is my xml file: Need in help in write proper xpath expression using query type xml
<?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="[email protected]"/>
</EMAILS>
</CONTACT>
<CONTACT>
<PDE-Identity>N65553</PDE-Identity>
<FirstName>GhorbelMahmoud</FirstName>
<LastName>Mahmoud Ghorbel</LastName>
<Facebook-ID/>
<EMAILS>
<EMail Domain="alcatel-lucent" Value="[email protected]"/>
</EMAILS>
</CONTACT>
<CONTACT>
<PDE-Identity>N65560</PDE-Identity>
<FirstName>keyankarthik</FirstName>
<LastName>karthik keyan</LastName>
<Facebook-ID/>
<EMAILS>
<EMail Domain="yahoo" Value="[email protected]"/>
</EMAILS>
</CONTACT>
<CONTACT>
<PDE-Identity>N65567</PDE-Identity>
<FirstName>Rangarajkarthik</FirstName>
<LastName>karthik Rangaraj</LastName>
<Facebook-ID/>
<EMAILS>
<EMail Domain="gmail" Value="[email protected]"/>
<EMail Domain="yahoo" Value="[email protected]"/>
</EMAILS>
</CONTACT>
<CONTACT>
<PDE-Identity>N65576</PDE-Identity>
<FirstName>ReddyAkky</FirstName>
<LastName>Akky Reddy</LastName>
<Facebook-ID/>
<EMAILS>
<EMail Domain="gmail" Value="[email protected]"/>
</EMAILS>
</CONTACT>
<CONTACT>
<PDE-Identity>N65597</PDE-Identity>
<FirstName>KumarVeera</FirstName>
<LastName>Veera_Kumar</LastName>
<Facebook-ID/>
<EMAILS>
<EMail Domain="yahoo" Value="[email protected]"/>
</EMAILS>
</CONTACT>
</CONTACTS>
My xul tree:
<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>
I couldn't write proper query to talk the email values according to the domain. Some one please help me...I have edited the previous question here..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常的方法是使用 XML 模板并自动生成树内容,请参阅 https://developer .mozilla.org/en/XUL/Template_Guide/XML_Templates 和 https://developer.mozilla.org/en/XUL/Template_Guide/XML_Assignments。在您的情况下,它会像这样工作:
请注意,如果您可以更改 XML 格式,这会更容易(不需要
标签)。如果将所有数据放入
标记的属性中,则无需显式分配变量即可访问它。看来您最终想实现树的动态过滤,这应该通过动态更改
标记的expr
属性来实现。您可以使用任何 XPath 表达式,例如expr="CONTACT[FirstName='Bob']"
将仅选择FirstName
子级值为Bob
的联系人代码>.The usual approach is using XML templates and have the tree contents generated automatically, see https://developer.mozilla.org/en/XUL/Template_Guide/XML_Templates and https://developer.mozilla.org/en/XUL/Template_Guide/XML_Assignments. In your case it would work like this:
Note that this would be easier (
<assign>
tags unnecessary) if you could change your XML format. If you put all the data into attributes of the<CONTACT>
tags you can access it without explicitly assigning variables.It seems that you want to implement dynamic filtering of the tree eventually, this should work by changing the
expr
attribute of the<query>
tag dynamically. You can use any XPath expression, e.g.expr="CONTACT[FirstName='Bob']"
will only select contacts withFirstName
child having the valueBob
.