Quick test professional

QTP Tips QTP codes QTP Faqs and more

How Get Root Element attribute’s value from XML file

How Get Root Element attribute’s value from XML file

Function GetRootElementAttributeValueFromXML(sFileNameWithPath,sAttribute)
    ‘ Why we need to ADD 2 because each attribute followed by (=) and (“)
            iLenOfValue=len(sAttribute) + 2
            Set doc = XMLUtil.CreateXML()
            doc.LoadFile sFileNameWithPath
            Set root = doc.GetRootElement()
            If instr(1,root,sAttribute)  <= 0 then
                        Reporter.ReportEvent micFail,sAttribute,”Not Found in XML file.”
                        exitrun(0)
            else      
                        sStartPos=instr(1,root,sAttribute) + iLenOfValue
                        sEndPos=instr(sStartPos,root,””””)
                        GetRootElementAttributeValueFromXML=mid(root,sStartPos,sEndPos – sStartPos)
            end if
End Function
msgbox(GetRootElementAttributeValueFromXML(“c:\temp\request.xml”,”MerchantId”))

Advertisements

February 14, 2008 - Posted by | XML Scripting

3 Comments »

  1. Hi Mohan,

    How to test an xml?

    I need to open an XML from and specific location and

    verify the data from the XML.

    How can i do this?

    Comment by Keerthy | December 8, 2008 | Reply

  2. Hi,

    Below i gave xml file . here we have two parent nodes “company”. under each node we have multiple child nodes. I am getting data from first parent node “company”, but can’t get the data from second parent node “company”. pls help on this.




    1-100091
    1-100091
    N
    Y
    skudder kemper
    Unassigned Division
    The Bank of New York Mellon

    skudder kemper
    DUMMY USER
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean nec ante sit amet dolor hendrerit cursus ut eget mauris. Phasellus dictum ornare eros, vel rutrum nibh euismod a. Maecenas pretium suscipit sapien ac malesuada. Vivamus id ultricies lorem. In hac habitasse platea dictumst. Aenean luctus turpis ac dolor dictum gravida. Duis leo magna, ultricies eu venenatis sed, tincidunt ac erat. Aliquam facilisis, arcu a suscipit bibendum, metus dui ornare tortor, non lobortis velit velit a orci. Mauris sed augue vel tellus iaculis congue accumsan ac dui. Sed libero sem, pellentesque vel scelerisque non, interdum ac nibh. Nunc nec nibh quis dolor vehicula pulvinar at eu lacus. Pellentesque in varius erat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;
    Cras blandit iaculis lectus eget luctus. Etiam ullamcorper massa nec justo bibendum malesuada. Quisque sed dolor eu sapien placerat pulvinar. Morbi volutpat justo nec diam facilisis tristique. Nullam at enim adipiscing libero iaculis luctus. Proin id nulla tortor, eget pretium tellus. Donec consequat adipiscing risus, nec porttitor velit sagittis ac. Integer viverra ullamcorper sem. Aliquam adipiscing justo sit amet quam pulvinar accumsan ultrices ante volutpat. Suspendisse tincidunt dapibus neque eget rutrum. Sed pulvinar orci sit amet turpis malesuada rhoncus ornare eros scelerisque. Mauris non tincidunt augue.
    Suspendisse purus dolor, aliquam vel mollis in, lacinia vel est. Phasellus pharetra pellentesque sapien sed consequat. Praesent vitae augue nisl. Praesent ligula tellus, vestibulum eget dignissim vitae, imperdiet id risus. Aenean quis nibh a mauris varius mattis. Sed interdum. Suspendisse purus dolor, aliquam vel mollis in, lacinia vel est. Phasellus pharetra pellentesque sapien sed consequat. Praesent vitae augue nisl. Praesent ligula tellus, vestibulum eget dignissim vitae, imperdiet id risus. Aenean quis nibh a mauris varius mattis. Sed interdum. Suspendisse purus dolor, aliquam vel mollis in, lacinia vel est. Phasellus pharetra pellentesque sapien sed consequat. Praesent vitae augue nisl. Praesent ligula tellus, vestibulum eget dignissim vitae, imperdiet id risus. Aenean quis nibh a mauris varius mattis. Sed interdum.
    2127023515

    Ins – Insurance

    Prospect

    N
    2008-12-11-10.48.14.000000
    Chris Hawkes
    James Lancet, Jr.
    2005-10-28-20.08.51.000000



    1-100091
    N
    Y
    Loria
    Joseph
    The Bank of New York Mellon
    Pershing
    VP
    201-413-3149

    National Customers
    East
    Jersey City


    1-100091
    N
    Y
    Brueckner
    Richard
    The Bank of New York Mellon
    Pershing
    SEVP
    2014133070

    National Customers
    East
    Jersey City


    1-100091
    N
    Y
    Smith
    Chris
    The Bank of New York Mellon
    Pershing
    AVP
    2014133847

    National Customers
    East
    Jersey City


    1-100091
    N
    Y
    Lee
    Linda
    The Bank of New York Mellon
    Pershing

    2014134269

    National Customers
    East
    Jersey City


    1-100091
    N
    Y
    Yuen
    Kammy
    The Bank of New York Mellon
    Depositary Receipts
    VP
    +85228409872


    1-100091
    N
    Y
    James
    Karen
    The Bank of New York Mellon
    EMEA – Asset Servicing

    +442071636783 000 000 000 0000


    1-100091
    N
    Y
    MacDonald
    Anthony
    The Bank of New York Mellon
    EMEA – Asset Servicing


    1-100091
    N
    Y
    Hawkes
    Chris
    The Bank of New York Mellon
    Strategic Sales
    VP
    +442071633228


    1-100091
    N
    Y
    Barcalow
    Scott
    The Bank of New York Mellon
    Treasury Services
    AVP
    2126357806


    1-100091
    Y
    Y
    USER
    DUMMY
    The Bank of New York Mellon
    Unassigned Division



    1-100091
    Y
    1-100094
    1-100094
    570 Lexington Ave
    10th Floor

    New York
    NY

    USA
    10022

    Symphonic Insurance, LLC


    1-100091
    N
    1-1BPO0A
    1-1BPO0A
    27 Chelidonous St.

    Kifisia 14561 Athens

    Australia
    14561


    +
    1-100GBX
    1-100GBX
    Y
    Y
    Setanta Asset Management Limited
    Global Markets
    The Bank of New York Mellon
    Canada Life
    Canada Life
    Michael Jesse

    Ins – Insurance

    Prospect

    N
    2009-12-15-19.01.32.000000
    Monika Raciborska
    Mick Murphy
    2005-10-31-07.14.32.000000



    1-100GBX
    Y
    Y
    Kirby
    Trevor
    The Bank of New York Mellon
    Global Markets
    VP



    1-100GBX
    Y
    1-100IJ4
    1-100IJ4
    College Park House
    20 Nassau Street

    Dublin 2

    Ireland

    Setanta Asset Management Limited

    Comment by Reddy | February 26, 2010 | Reply

  3. abzqod vinuwn ahlpwa
    courtage forex kvuqij

    Comment by glinger | September 30, 2013 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: