Solved

ASP XML using GetNamedItem

Posted on 2011-02-14
4
541 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
Comment Utility
account_number isn't an attribute of the "row" element, it is a child element of the "row" element.
0
 

Author Comment

by:kishan66
Comment Utility
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
Comment Utility
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
Comment Utility
You are awesome

Thank you somuch
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now