开发者

jQuery extracting attributes from xml document

开发者 https://www.devze.com 2023-03-02 15:58 出处:网络
I\'m a javascript / JQuery newbie, so I hope this is obvious to you guys. I\'m trying to implement javascript / JQuery based translation of html documents.

I'm a javascript / JQuery newbie, so I hope this is obvious to you guys. I'm trying to implement javascript / JQuery based translation of html documents. Given this xml document with translations:

<definitions>
  <parameters>
    <parameter name="misc.gain" caption="Gain"/>
    <parameter name="mis开发者_开发技巧c.integral" caption="Integration time"/>
  </parameters>
</definitions>

In my script, I have found an element that needs to be translated. The above document is in xlmdocument.

var my_id = $( this ).attr('id');  // ="misc.gain" on first iteration
// find xml node whose name is = my_id from xmldocument
// extract caption attribute from xml node
$( this ).html( translatedcaption); // 

Can someone give me a hint, I'm kind of stuck here.

Edit : A nice guy provided me with hint and direction, don't know why he deleted his post.

My final solution was:

   var my_id = $( this ).attr('id');
   var xmlnode = $(xmldocument).find("parameter[name='" + my_id + "']");
   $( this ).html($(xmlnode).attr("caption"));

Thanks for your quick help Mr. X


A nice guy provided me with hint and direction, don't know why he deleted his post.

My final solution was:

   var my_id = $( this ).attr('id');
   var xmlnode = $(xmldocument).find("parameter[name='" + my_id + "']");
   $( this ).html($(xmlnode).attr("caption"));

Thanks for your quick help Mr. X

0

精彩评论

暂无评论...
验证码 换一张
取 消