Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old June 7th, 2007, 10:01 AM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

  #2 (permalink)  
Old June 7th, 2007, 11:02 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
  #3 (permalink)  
Old June 8th, 2007, 02:55 AM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

  #4 (permalink)  
Old June 8th, 2007, 03:34 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
  #5 (permalink)  
Old June 8th, 2007, 04:04 AM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

  #6 (permalink)  
Old June 8th, 2007, 04:13 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
  #7 (permalink)  
Old June 8th, 2007, 04:34 AM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


  #8 (permalink)  
Old June 8th, 2007, 04:53 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
  #9 (permalink)  
Old June 8th, 2007, 05:20 AM
Authorized User
 
Join Date: Jan 2007
Location: , , .
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

  #10 (permalink)  
Old June 8th, 2007, 05:53 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)




Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in reading xml database balaguru XML 0 May 29th, 2007 02:41 AM
reading a XML file connect2sandep XML 1 December 14th, 2006 04:50 AM
reading a XML file connect2sandep General .NET 0 December 13th, 2006 02:10 PM
Reading XML evidica C# 0 July 25th, 2006 10:33 AM
Reading XML from ASP texasraven Classic ASP XML 2 February 26th, 2004 03:26 PM





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