Forum Discussion

ssa's avatar
ssa
Occasional Contributor
10 years ago

getting an node's value from XML file.


My XML file's structure is like this...



<?xml version="1.0" encoding="utf-8" ?>


<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:core="http://x.y.com/xy/xyz">


  <atom:title>TestTitle</atom:title>


  <atom:link rel="a" href="$a_u"/>


  <atom:link rel="ot" href="$ou"/>


  <atom:link rel="db" type="app/c.d.p+xml" href="e.xml">


    <atom:inline>



        <field name="asset.title">


          <value>DP</value>


        </field>


        <field>


          <value>xxx</value>


        </field>


        |


        |


        |


     </atom:inline>


  </atom:link>


</atom:entry>


I am trying to get the value "DP" of file whose name="asset.title"



Followed this Doc's but no luck..



http://support.smartbear.com/viewarticle/57106/



http://support.smartbear.com/viewarticle/58850/



How can i get this value. Thanks in advance for any pointer or help.


2 Replies

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)
    Hi Suvasish,

     


    Check how the sample below works for you:


     




    //JScript


    function test()


    {


      var fileName = "c:\\test.xml";


      var doc = Sys.OleObject("Msxml2.DOMDocument.6.0");


      doc.setProperty("SelectionNamespaces", "xmlns:atom='http://www.w3.org/2005/Atom' xmlns:ns='http://www.yyy.com/xxx'");


      doc.load(fileName);


     


      var value = doc.selectSingleNode("/atom:entry/atom:inline/ns:payload/ns:field[@name='asset.title']/ns:value").text;


      Log.Message(value);


    }



  • ssa's avatar
    ssa
    Occasional Contributor


    Getting this error messge if i try as mentioned...



    In this tline..



      var value = doc.selectSingleNode("/atom:entry/atom:inline/ns:payload/ns:field[@name='asset.title']/ns:value").text;



    Error:



    Object required



    Note: I've MSXML 4.0 SP3 Parser installed on by system. (Win 7 64 bit). 



    So i made this change on your code.



    var doc = Sys.OleObject("Msxml2.DOMDocument.4.0"); 


     //var doc = Sys.OleObject("Msxml2.DOMDocument.6.0");