|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
ASP using XML
ok i think i have it figured out how to produce an xml file. now how do i encorporate that into an asp file? such as using it to populate an option box. or just plain outputing it to the screen. i've looked at a couple of ways to do it with vbscript and javascript but none of them seemed to work to create option boxes in a form that will actually work. anyone have any sample code or know a site that shows how to do it?
__________________
My brain cells are like a storm trooper's armor: useless |
|
#2
|
|||
|
|||
|
here's a chunk of code that parses a xml DOM...
i raped it a bit and since it's a piece it will not do anything in it's state, but its a decent base to go from... see 3rd post ![]() Last edited by mad8vskillz : August 18th, 2003 at 04:13 PM. |
|
#3
|
||||
|
||||
|
uh, thanks i think.
anyone else have anything? or maybe an explaination of the code listed? |
|
#4
|
|||
|
|||
|
ok, i'll try trimming it to what you will need
![]() Code:
Set objSource = Server.CreateObject("Microsoft.XMLDOM") 'create the sqlreaderthingy
'get XML string (so that you can do something with it)
strXML=somefunction()
'just some stuff you need
objSource.async = false
objSource.loadXML strXML
'retrieve data for table OR report eof
If ((objSource.readyState = 4) AND (objSource.parseError.errorCode = 0)) Then
Set rootElement = objsource.documentElement 'for shorter xmldom calling
if rootelement.getElementsByTagName("z:row").length-1=0 then 'check if rst is empty
%>
Your Search did not find any matching records. Please press back button to try again
<%
else 'records found, build table
for i=0 to rootelement.getElementsByTagName("z:row").length-1 'go through the xml
firstname=rootelement.getElementsByTagName("z:row").item(i).getattribute("firstname") 'get firstname (can be any other field) from xml
response.write(firstname) 'do something with name
next
end if
sorry about formating, my pc is weird ![]() |
|
#5
|
|||
|
|||
|
Hi Don,
here is a more simpler way of acheiving it. The combo box that i am filling is just an INFO purpose and the length of the combo box is 5 which means users can see 5 values at a time. We can certainly add "select one" at the top of a huge list of values. function populatetgexstCombo(par) { var tgs; //Data ISLAND to be declared in the body of the html and set it to asynchronous data read mode. XMLtgexstID.async = false; // Change Ddata Island source XMLtgexstID.SRC="/<%=approot%>/data/tgexistslist.asp?coloid="+ par; // Get recordset from XML data var tgs = XMLtgexstID.getElementsByTagName("z:row"); // Fill combo with what is needed for (var i=0; i < tgs.length; i++) { if (tgs.item(i).attributes(1).text !="") { form.combo.options[i]=new Option(tgs.item(i).attributes(1).text ,tgs.item(i).attributes(0).text); }//end if }//end for // Delete extra entries while (tgs.length < form.combo.options.length) { form.combo.options[(step3.tgExst.options.length-1)] = null; } //end while }//END FUNCTION and after the body tag in the html/asp page add this < XML ID="XMLtgexstID" > </XML> --------------------------------------------------------------- Hope that helps. Let me know if you have any questions regarding the script |
|
#6
|
|||
|
|||
|
If you created your xml file by saving an ado recordset as an xml file, you can simply create an ado recordset on another page and rs.open "myxmlfile.xml" from the previously stored ado xml. Then use the recordset as if you just got it from a database.
|
|
#7
|
|||
|
|||
|
|
|
#8
|
||||
|
||||
|
the more i look at xml the more i get confused. writing the schemas is easy enough, but how the heck do you get anything out of it. sure you can output it, but is there anyway to use asp to get the information you need? here is what i really want. take this schema:
Code:
<?xml version="1.0" ?> - <Hardware> - <Listing> <HardwareID>1</HardwareID> <Manufacturer>Compaq</Manufacturer> <Product>EVO</Product> </Listing> - <Listing> <HardwareID>2</HardwareID> <Manufacturer>IBM</Manufacturer> <Product>T30</Product> </Listing> - <Listing> <HardwareID>3</HardwareID> <Manufacturer>Sony</Manufacturer> <Product>Vaio</Product> </Listing> </Hardware> and put it into this Code:
<form name="form1">
<select name="select1">
<option value="<!--hardwareID-->"><!-- this is where the manufacturer and the product go, concatinated--></option>
</select>
<input type="submit" name="submit" value="submit">
</form>
no help from the xml forum so far. should this be easier, or at least possible to do if xml is going to be the next best thing? yeah i'm frustrated. ![]() |
|
#9
|
|||
|
|||
|
try messing with this (i did this in notepad, so it might be a little wrong)
Code:
<%@ Language=VBScript %>
<%
Set objSource = Server.CreateObject("Microsoft.XMLDOM") 'create the sqlreaderthingy
'get XML string (so that you can do something with it)
strXML="<?xml version=1.0 ?>"
strXML=strXML+"- <Hardware>"
strXML=strXML+"- <Listing>"
strXML=strXML+" <HardwareID>1</HardwareID> "
strXML=strXML+" <Manufacturer>Compaq</Manufacturer> "
strXML=strXML+" <Product>EVO</Product> "
strXML=strXML+" </Listing>"
strXML=strXML+"- <Listing>"
strXML=strXML+" <HardwareID>2</HardwareID> "
strXML=strXML+" <Manufacturer>IBM</Manufacturer> "
strXML=strXML+" <Product>T30</Product> "
strXML=strXML+" </Listing>"
strXML=strXML+"- <Listing>"
strXML=strXML+" <HardwareID>3</HardwareID> "
strXML=strXML+" <Manufacturer>Sony</Manufacturer> "
strXML=strXML+" <Product>Vaio</Product> "
strXML=strXML+" </Listing>"
strXML=strXML+" </Hardware>"
objSource.async = false
objSource.loadXML strXML
'retrieve data for table OR report eof
If ((objSource.readyState = 4) AND (objSource.parseError.errorCode = 0)) Then
Set rootElement = objsource.documentElement 'for shorter xmldom calling
if rootelement.getElementsByTagName("listing").length-1=0 then 'check if rst is empty
%>
Your Search did not find any matching records. Please press back button to try again
<%
else 'records found, build select
%>
<form name="form1">
<select name="select1">
<%
for i=0 to rootelement.getElementsByTagName("listing").length-1 'go through the xml
hardwareid=rootelement.getElementsByTagName("listing").item(i).getattribute("HardwareID")
manufacturer=rootelement.getElementsByTagName("listing").item(i).getattribute("Manufacturer")
product=rootelement.getElementsByTagName("listing").item(i).getattribute("Product")
%>
<option value="<%=hardwareid%>"><%=manufacturer%>, <%=product%></option>
<%
next
end if
end if
%>
</select>
<input type="submit" name="submit" value="submit">
</form>
|
|
#10
|
|||
|
|||
|
Don, Ok, since you said, you know how to create an xml file, I didnot think you needed this information.
Here is how the XML file is created. you can use ado's adpersistxml parameter in rs.save to get an xml file and it is quite easy to manipulate with the script I gave you below. the name of this file is tgexistslist.asp ( src of the xml data island in the script below) <%@ Language=VBScript %> <% Response.ContentType="text/xml" %> <!--#include file='conmanager.inc'--> <!--#include file='getXML.inc'--> <% dim strSQL dim scoloID scoloID=Request.QueryString("coloID") if Request.QueryString("coloID").Count=0 then Response.Write "<xml xmlns:z=""#RowsetSchema""><z:row ID=""0"" COLO=""-N/A-"" /></xml>" else strSQL = "select tg.id,tg.trunkgroup"&_ " from trunkgroup_header tg"&_ " where tg.colo_id=" & scoloID &_ " order by tg.trunkgroup" end if response.write getXMLData(strsql,"dbconnection") function getXMLData(strSQL, conName) on error resume next dim oStr, oRS, oCon, strConn, oops Response.Write("<?xml version='1.0'?>" & vbCrLf) set oCon = getConnection(conName) set oRS = server.CreateObject("ADODB.Recordset") oRS.Open strSQL, oCon set oStr = Server.CreateObject("ADODB.Stream") oStr.Open oRS.Save oStr, 1 if err.number = 0 then getXMLData = oStr.ReadText else oops = "<xml>" oops = oops & "<error>Database lookup failed. Check your connection parameters and query syntax.</error>" oops = oops & "<sqlstring><![CDATA[" & strSQL & "]]></sqlstring>" oops = oops & "<uname>" & dbUser & "</uname>" oops = oops & "<pass>" & dbPass & "</pass>" oops = oops & "<tnsname>" & tnsName & "</tnsname>" oops = oops & "</xml>" getXMLData = oops end if oStr.Close set oStr = nothing oRS.Close set oRS = nothing end function %> <!--#include file='concleanup.inc'--> Quote:
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > ASP using XML |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|