p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XML (http://p2p.wrox.com/forumdisplay.php?f=91)
-   -   problem reading a value from an xml (http://p2p.wrox.com/showthread.php?t=58829)

mrjoka June 7th, 2007 10:01 AM

problem reading a value from an xml
dear experts, thanks for the help till now.
i'm working with an xml file, first i called the xml file, it is empty, the user entered some values in a form and then i parse these values to the xml, when this information is parsed to the xml, the location id is automatically generated, now i need to get this locationid and store it in database.
here is the xml i get:
 <?xml version="1.0" encoding="UTF-8" ?>
- <Response type="location.add" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://tools.finder.xml.addlocation.asp">
- <location id="3088479" marker_id="0" score="0" published="0" refid="">
- <address>
  <phone />
  <fax />
  <email />
  <internet />
  <memo />
  <image />
- <properties>
  <propertygroup id="200" name="Pharmacies" />
  <propertygroup id="201" name="UPO" />

the user enters all the field but the location is generated automatically.

i used:
set location_id = xmlObj.getElementsByTagName("location_id")
and in the query i'm using insert into tabe (location_id,....0 values (location_id)
i've been working in this problem for a logn time now. any help will be appreciated.

joefawcett June 7th, 2007 11:02 AM

Well you can use getElementsByTagName but that returns a collection and works on elements. You don't have an element called location_id so you need:

set colLocation = xmlObj.getElementsByTagName("location")
Set firstLocation = colLocation.Item(0)
Response.Write firstLocation.getAttribute("id")

It would be better to try to learn XPath, it's much more flexible:

Response.Write xmlObj.selectSingleNode("/Response/location/@id").nodeValue

Joe (Microsoft MVP - XML)

mrjoka June 8th, 2007 02:55 AM

hi my friend, thanks for the quick reply, i did try what you told me but i get the following error:
Microsoft VBScript runtime error '800a01a8'

Object required: 'xmlObj'

/functions/app/admin/MapAdmin.asp, line 119
 it is in: set colLocation = xmlObj.getElementsByTagName("location") any idea about that? also i want to store this value into a variable so i can store it in my database.

joefawcett June 8th, 2007 03:34 AM

Well your original code had a reference to xmlObj in it, I rashly presumed that you'd declared it and loaded the XML already. Why didn't you get the error message then?


Joe (Microsoft MVP - XML)

mrjoka June 8th, 2007 04:04 AM

yes my friend, you were write, while i was doing some test i removed it and now it is working. thanks.
last question: how can i store this id into a variable so i can save it into a database because when i'm inserting: firstLocation.getAttribute("id") it is not working and when i insert just firstLocation nothing is saved into a database.


joefawcett June 8th, 2007 04:13 AM


Dim locationId 'as string
set colLocation = xmlObj.getElementsByTagName("location")
Set firstLocation = colLocation.Item(0)
locationId = firstLocation.getAttribute("id")

If that doesn't work show your SQL statement, use a Response.Write to display it before you actually call it.


Joe (Microsoft MVP - XML)

mrjoka June 8th, 2007 04:34 AM

thanks now i can store the value into locationid, actually i have a sub for addLocation() and a function for Savedata() what i did is : in sub Addlocation() i declare
Location_id = Session("locationid")
and in the query i did insert into (location_id, ......) values (Location_id, ......0 but i'm still getting nothing in the database.

here is the query:
INSERT INTO tblcities (Location_id, locationname, street, housenr, postcode, city, phone, fax, email, internet, properties, X, Y, marker_id, status, Publish, RefID, Memo, TimeStamp, UserStamp) VALUES ('', 'hjg', 'ghj', 'ghj', 'ghj', 'ghjghj', '', '', '', '', '', '', '', '', '', '', '', '', '6/8/2007 11:33:30 AM', '16')

i hope you can help.

joefawcett June 8th, 2007 04:53 AM

So what do addLocation() and SaveData() look like? You don't need to use a session variable if it's in the same page, just pass it to the sub. Sounds like you don't have Option Explicit declared and your variable is out of scope.


Joe (Microsoft MVP - XML)

mrjoka June 8th, 2007 05:20 AM

the addlocation is calling an xml file and the user enter some information into the form and these information is saved in the database and the xml generate the locationid automatically. the savedata() is just an insert query.

i did declare my variables in the top of the page but do i need to put: <% option explicit%> ?
is that what you mean?

joefawcett June 8th, 2007 05:53 AM

You don't have to put it in but if you do you will get error messages pointing out undeclared variables which maybe your problem. What do the two subs look like?


Joe (Microsoft MVP - XML)

All times are GMT -4. The time now is 08:48 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.