Solved

ASP XML using GetNamedItem

Posted on 2011-02-14
4
543 Views
Last Modified: 2012-05-11
Hi,

i am trying to read through XML file using ASP.

when used ChildNodes , could retrieve data without fail / Exceptions.
I want to use getNamedItem instead of ChildNodes.

getting 'ObjectRequired' Exception when using --->  rows(i).Attributes.GetNamedItem("account_number").value

where

Set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = False
objXML.Load (Server.MapPath("ACCT_02102011.xml"))
Set rows = objXML.getElementsByTagName("row")

and also i would appreciate if you can help me in error handling in the absence of a tag.

pls refer to my XML data for further info...

Thanks

<<<<<<<ACCT_02102011.xml>>>>>

<Main>
<row>
<account_number>AAT000021</account_number><cusip>3345679</cusip><symbol>SHV</symbol><description>ISHARES TR BARCLAYS SHORT TREAS BD FD</description><start_qty>0.000000000000000e+000</start_qty><end_qty>0.000000000000000e+000</end_qty><avg_price>0.000000000000000e+000</avg_price><cost_basis>0.000000000000000e+000</cost_basis><pnl_daily>0.000000000000000e+000</pnl_daily><pnl_mtd>0.000000000000000e+000</pnl_mtd><pnl_ytd>-3.598040000000000e+001</pnl_ytd><shares_traded_mtd>0</shares_traded_mtd>
</row>
<row><account_number>AAZ000021</account_number><cusip>026874156</cusip><symbol>AIG WS</symbol><description>AMERICAN INTL GROUP INC WT EXP 01/19/2010</description><start_qty>1.100000000000000e+001</start_qty><end_qty>1.100000000000000e+001</end_qty><avg_price>1.629000000000000e+001</avg_price><cost_basis>1.791900000000000e+002</cost_basis><pnl_daily>6.600000000000000e-001</pnl_daily><pnl_mtd>9.900000000000000e-001</pnl_mtd><pnl_ytd>-1.848000000000000e+001</pnl_ytd><shares_traded_mtd>0</shares_traded_mtd>
</row>
</Main>

Open in new window

0
Comment
Question by:kishan66
  • 2
  • 2
4 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34889299
account_number isn't an attribute of the "row" element, it is a child element of the "row" element.
0
 

Author Comment

by:kishan66
ID: 34890028
Hi carl,

Thanks for the reply.

Sorry for my lack of knowledge in ASP XML.

So, is there a way to access those 'child elements' by name?  pls suggest me one.

Also guide me the best way to check if the 'child element' is present or not.
ex:- IF there is no <cusip> tag (child element)  in the "row"
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 34890129
Since you appear to be using it in a loop, you could use something like:
'// retrieve the "account_number" child element
Set child = rows(i).selectSingleNode("account_number")

'// check if the node exists
If Not child Is Nothing 
   someVariable = child.Text
End If

Open in new window

0
 

Author Closing Comment

by:kishan66
ID: 34890392
You are awesome

Thank you somuch
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question