一道面试题

We are hiring intermediate or experienced Java/Jscript programmers right now. And we hope you can demonstrate your experience/learning ability by solving the problem below. It'll be a jscript function to transform a given format of XML input to another XML format.
 
The input would be like:  

 

xml 代码
  1. xml version="1.0"?>    
  2. <menu xmlns="">    
  3.     <menuitem>    
  4.         <node>1node>    
  5.         <parent>1parent>    
  6.         <name>parentname>    
  7.     menuitem>    
  8.     <menuitem>    
  9.         <node>2node>    
  10.         <parent>1parent>    
  11.         <name>1st childname>    
  12.     menuitem>    
  13.     <menuitem>    
  14.         <node>3node>    
  15.         <parent>1parent>    
  16.         <name>2nd childname>    
  17.     menuitem>    
  18.     <menuitem>    
  19.         <node>4node>    
  20.         <parent>2parent>    
  21.         <name>grantchildname>  
  22.    <attr1>helloattr1>  
  23.    <attr2>Worldattr2>  
  24.     menuitem>    
  25. menu>   

 
The output would be like: 
 
xml 代码
  1. xml version="1.0"?>    
  2. <menu xmlns="">    
  3.     <menuitem>    
  4.         <name>parentname>    
  5.         <menuitem>    
  6.             <name>1st childname>    
  7.             <attr1>helloattr1>  
  8.             <attr2>Worldattr2>  
  9.             <menuitem>    
  10.                 <name>grand childname>    
  11.             menuitem>    
  12.         menuitem>    
  13.         <menuitem>    
  14.             <name>2nd childname>    
  15.         menuitem>    
  16.     menuitem>    
  17. menu>   


 
In the input format, tag "node" and "parent" specifies the structure of the tree, while "name" and others tags should be copied to the output format.  Therefore, the code should be able to handle the following fragment of XML:

 

xml 代码

 

  1. <menuitem>    
  2.         <node>2node>    
  3.         <parent>1parent>    
  4.         <name>1st childname>    
  5.         <lastName>XialastName>    
  6.         <firstName>HaofirstName>    
  7. menuitem>  


  For information on how to manipulate XML with jscript, you can check out MSDN's relevant section.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值