Solved

ASP XML using GetNamedItem

Posted on 2011-02-14
4
547 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 informatio…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

635 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