select single attribute value from multiple with condition query type xml in XUL 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="nura_e@yahoo.co.in"/>
</EMAILS>
</CONTACT>
<CONTACT>
<PDE-Identity>N65553</PDE-Identity>
<FirstName>GhorbelMahmoud</FirstName>
<LastName>Mahmoud Ghorbel</LastName>
<Facebook-ID/>
<EM开发者_如何学编程AILS>
<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>
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..
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:
<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>
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 with FirstName
child having the value Bob
.
精彩评论