SitePoint Sponsor |
|
User Tag List
Results 1 to 19 of 19
Thread: import xml with asp
-
Nov 10, 2006, 07:52 #1
import xml with asp
I am trying to import some xml into an asp page for manuipulation. I have:
Code:<% Dim xmlDoc Set xmlDoc=Server.CreateObject("Microsoft.XMLDOM") xmlDoc.async=false xmlDoc.load(Server.MapPath("xmldata/2006-07_JUL-SEP.xml")) xmlDoc.load(Request) If xmlDoc.parseError.errorcode<>0 then 'error handling code Response.Write(xmlDoc.parseError.errorcode) Else 'proceed Response.Write("Everthing OK so far!") End If %>
error = -1072896680
is it obvious where i'm going wrong (the xml is valid)?
monkeymonkey - the rest is history
-
Nov 10, 2006, 08:44 #2
- Join Date
- Nov 2001
- Location
- The Central Plains
- Posts
- 3,304
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
first thing to do is open the xml file in IE, of there is a problem, it will let you know.
-
Nov 10, 2006, 08:45 #3
- Join Date
- Nov 2001
- Location
- The Central Plains
- Posts
- 3,304
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
and is that error being written by this line: Response.Write(xmlDoc.parseError.errorcode) or does it point to a different line in your script?
-
Nov 10, 2006, 08:46 #4
done that - and run it through the w3c xml validator and everthing seems fine. seems to work if I remove the line:
xmlDoc.load(Request)
What I need is a good tutorial on how I can manipulate the data and use it in my asp code.
cheers
the response.write linemonkey - the rest is history
-
Nov 10, 2006, 08:52 #5
- Join Date
- Nov 2001
- Location
- The Central Plains
- Posts
- 3,304
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
http://msdn.microsoft.com/xml/default.aspx
there is an sdk/help file that can be download with all the code samples that you'd ever want. also maybe check out the "code samples" link.
-
Nov 10, 2006, 08:56 #6
- Join Date
- Nov 2001
- Location
- The Central Plains
- Posts
- 3,304
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
you also might check out here: http://www.4guysfromrolla.com/webtech/101200-1.2.shtml
-
Nov 10, 2006, 09:52 #7
Cheers bill
I have already read the 4guysfromrolla article (the MSDN site keeps crashing on me!!!) and a few others, but they all seem to eaither use the xsl to display the entire xml data, or just write the whole lot out using asp.
I need far more control over the data, targeting the data in spacific elements. Treating it more like a recordset.
any ideas
cheersmonkey - the rest is history
-
Nov 10, 2006, 10:30 #8
- Join Date
- Nov 2001
- Location
- The Central Plains
- Posts
- 3,304
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
it's been a while since i've done it, but with MSXML you can target individual nodes or even return node collections. check into the sdk, not sure where it is on the site anymore. maybe do a google on the msxml sdk
-
Nov 10, 2006, 10:36 #9
- Join Date
- Nov 2001
- Location
- The Central Plains
- Posts
- 3,304
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
hey, here's an article on SP: http://www.sitepoint.com/article/mic...developers-1/2
-
Nov 10, 2006, 10:38 #10
top man - i'll give it a read - cheers
monkey - the rest is history
-
Nov 13, 2006, 12:22 #11
- Join Date
- Oct 2006
- Location
- San Francisco, CA
- Posts
- 38
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I was curious as to why you even had that line
xmlDoc.load(Request)
The other load call is the on the one you want.
I see you are using the XMLDom so it uses pretty standard methods for accessing elements, tags and some
xmlDoc.getElementById
xmlDoc.getElementsByTagName
xmlDoc.childNodes
etc.
W3schools is always a great reference for this kind of stuff:
http://w3schools.com/dom/default.asp
-
Nov 27, 2006, 10:23 #12
I have been reading the w3schools tutorials, but they are all in javascript and from what I can tell, I should be able to do the same thing in asp vbscript.
I am trying:
Code:<% Dim xmlDoc Set xmlDoc=Server.CreateObject("Microsoft.XMLDOM") xmlDoc.async=false xmlDoc.load(Server.MapPath("xmldata/myxmlfile.xml")) If xmlDoc.parseError.errorcode<>0 then 'error handling code Response.Write(xmlDoc.parseError.errorcode) Else 'proceed Response.Write(xmlDoc.getElementsByTagName("DataReturn")) End If %>
cheersmonkey - the rest is history
-
Nov 27, 2006, 12:51 #13
- Join Date
- Nov 2004
- Location
- Nelson BC
- Posts
- 2,310
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Response.Write xmlDoc.getElementsByTagName("DataReturn").xml
-
Nov 28, 2006, 04:35 #14
Originally Posted by jimfraser
monkey - the rest is history
-
Nov 29, 2006, 17:49 #15
- Join Date
- Nov 2004
- Location
- Nelson BC
- Posts
- 2,310
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How about
xmlDoc.selectSingleNode("DataReturn").xml
-
Nov 30, 2006, 07:42 #16
fantastic!
How do I move down through the tree? ie:
<dataReturn>
<node></node>
</dataReturn>
How do i get to node?
cheers for your helpmonkey - the rest is history
-
Nov 30, 2006, 13:26 #17
- Join Date
- Nov 2004
- Location
- Nelson BC
- Posts
- 2,310
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
either
Code:Set oMyNode = xmlDoc.selectSingleNode("dataReturn/node") Response.Write oMyNode.xml
Code:Set oDataReturn = xmlDoc.selectSingleNode("dataReturn") Set oMyNode = oDataReturn.selectSingleNode("node") etc
-
Dec 6, 2006, 05:22 #18
cheers - started to get to grips with it now
How do I get a list of attribute for a set of node (sorry, not sure of the language to use!)
so if i have:
<mynode>
<child attribute="x">45</child>
<child attribute="y">12</child>
</mynode>
I would like an array of the attributes or, better still, be able to loop through every child in a certain node and response.write the attribute value such as
for each child in mynode
response.write("attribute.value"&"</br>")
response.Write(xmlDoc.selectSingleNode("mynode/child[@attribute="&attribute.value&"]")
next
if you see what i mean
cheersmonkey - the rest is history
-
Dec 6, 2006, 07:36 #19
- Join Date
- Nov 2004
- Location
- Nelson BC
- Posts
- 2,310
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
for each child in mynode.selectNodes("child")
response.write("attribute.value"&"</br>")
response.Write(child.getAttribute("attribute"))
next
Bookmarks