Solved

ASP XML using GetNamedItem

Posted on 2011-02-14
4
546 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error in query expression 3 57
Passing Parameter to Stored Procedure 4 41
alert(innerHTML); 8 45
Designing forms 3 70
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…
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/…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 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