Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP XML using GetNamedItem

Posted on 2011-02-14
4
Medium Priority
?
548 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

705 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