 |
| XML General XML discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 7th, 2007, 10:01 AM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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="">
<locationname> vb</locationname>
- <address>
<street>cvb</street>
<housenr>cvb</housenr>
<postcode>cvb</postcode>
<city>cvb</city>
<country>NL</country>
</address>
<phone />
<fax />
<email />
<internet />
<memo />
<image />
- <properties>
<propertygroup id="200" name="Pharmacies" />
<propertygroup id="201" name="UPO" />
</properties>
</location>
</Response>
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.
thanks
|
|

June 7th, 2007, 11:02 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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:
Code:
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:
Code:
Response.Write xmlObj.selectSingleNode("/Response/location/@id").nodeValue
--
Joe ( Microsoft MVP - XML)
|
|

June 8th, 2007, 02:55 AM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
thanks
|
|

June 8th, 2007, 03:34 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

June 8th, 2007, 04:04 AM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
thanks
|
|

June 8th, 2007, 04:13 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Code:
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)
|
|

June 8th, 2007, 04:34 AM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi,
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.
thanks
|
|

June 8th, 2007, 04:53 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|

June 8th, 2007, 05:20 AM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
thanks
|
|

June 8th, 2007, 05:53 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
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)
|
|
 |