在 XUL 树中使用条件查询类型 xml 从多个属性值中选择单个属性值

发布于 2024-11-16 20:20:08 字数 4221 浏览 5 评论 0原文

这是我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溺孤伤于心 2024-11-23 20:20:08

通常的方法是使用 XML 模板并自动生成树内容,请参阅 https://developer .mozilla.org/en/XUL/Template_Guide/XML_Templateshttps://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 格式,这会更容易(不需要 标签)。如果将所有数据放入 标记的属性中,则无需显式分配变量即可访问它。

看来您最终想实现树的动态过滤,这应该通过动态更改 标记的 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:

 <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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文