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="">
  <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


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:
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)

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.
thanks


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.

thanks


joefawcett June 8th, 2007 04:13 AM

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)

mrjoka June 8th, 2007 04:34 AM

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



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?
thanks


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)

mrjoka June 8th, 2007 09:41 AM

hi, sorry for the late reply, i was out of the office.
i do not have any kind of errors when running the page but when i check the database i do not find records for locationid

in the begining of the page i declare my variables:
dim locationid

i have a sub:
sub Addlocation()

xmlReq = "http://tools.locatienet.com/xml.1/finder/Addlocation.asp"
    xmlReq = xmlReq & "&locationname=" & request.form("Naam")
    xmlReq = xmlReq & "&street=" & request.form("Straatnaam")
    xmlReq = xmlReq & "&housenr=" & request.form("Huisnummer")
    xmlReq = xmlReq & "&postcode=" & request.form("Postcode")
    xmlReq = xmlReq & "&city=" & request.form("City")
    xmlReq = xmlReq & "&phone=" & request.form("Telefoon")
    xmlReq = xmlReq & "&fax=" & request.form("Fax")
    xmlReq = xmlReq & "&internet=" & request.form("Website")
    xmlReq = xmlReq & "&email=" & request.form("sEmail")
    xmlReq = xmlReq & "&memo=" & request.form("Memo")
    xmlReq = xmlReq & "&properties=" & request.form("Eigenschappen")

    set xmlObj = getXMLDocument(xmlReq)

    set colLocation = xmlObj.getElementsByTagName("location")
    Set firstLocation = colLocation.Item(0)
    locationid = firstLocation.getAttribute("id")
if xmlObj is Nothing or Not IsObject(xmlObj) then
        exit sub
    end if
end sub

and at the end of the class i have a function:

function Savedata()

lSQL = " INSERT INTO tblLocations "&_
                " (Location_id, "&_
                " locationname, "&_
                " street, "&_
                " housenr, "&_
                " postcode, "&_
                " city, "&_
                " phone, "&_
                " fax, "&_
                " email, "&_
                " internet, "&_
                " properties, "&_
                " X, "&_
                " Y, "&_
                " marker_id, "&_
                " status, "&_
                " Publish, "&_
                " RefID, "&_
                " Memo, "&_
                " TimeStamp, "&_
                " UserStamp) "&_
                " VALUES "&_
                " ('" &objDB.cv(locationid) &"'," &_
                " '" &objDB.cv(Naam) &"'," &_
                " '" &objDB.cv(Straatnaam) &"'," &_
                " '" &objDB.cv(Huisnummer) &"'," &_
                " '" &objDB.cv(Postcode) &"'," &_
                " '" &objDB.cv(City) &"'," &_
                " '" &objDB.cv(Telefoon) &"'," &_
                " '" &objDB.cv(Fax) &"'," &_
                " '" &objDB.cv(sEmail) &"'," &_
                " '" &objDB.cv(Website) &"'," &_
                " '" &objDB.cv(Eigenschappen) &"'," &_
                " '" &objDB.cv(X) &"'," &_
                " '" &objDB.cv(Y) &"'," &_
                " '" &objDB.cv(Marker) &"'," &_
                " '" &objDB.cv(status) &"'," &_
                " '" &objDB.cv(Publish) &"'," &_
                " '" &objDB.cv(RefID) &"'," &_
                " '" &objDB.cv(Memo) &"'," &_
                " '" &objDB.cv(now()) &"'," &_
                " '" &objDB.cv(Session("UserID")) &"')"

                objDB.insert(lSQL)
end function

i hope you can help me with this. i hope i can declare it globally so i can use it in the form as much as i like.

thanks


joefawcett June 8th, 2007 10:21 AM

So how is objDB populated?

--

Joe (Microsoft MVP - XML)

mrjoka June 8th, 2007 10:27 AM

it is in an include, all the connection with the database is maintained in the include, all the fields inserted without a problem except for locationid.

any idea what might be?

thanks for your time.


joefawcett June 8th, 2007 10:34 AM

It's like pulling teeth...
What is objDB.cv? Why should locationId have a value within SaveData?
From within SaveData do a Response.Write of locationId and objDB.cv(locationId).

--

Joe (Microsoft MVP - XML)

mrjoka June 8th, 2007 10:48 AM

i found the error, it seems that value has been overwrite somewhere, it was declared more that once, i did fix it and now it's working good.
thank you for the help and have a nice week end

thanks



All times are GMT -4. The time now is 09:05 PM.

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