Solved

<Help><language>XML, classic ASP</language> <state>a major disconnect.</state></Help>

Posted on 2004-09-19
13
305 Views
Last Modified: 2013-11-19
Before you think this may be a piece of cake, my question is a bit longwinded, but a great opportunity to set the record straight!

I could really use some help and guidance.  Here is what I am looking to accomplish.  I need to get a reasonable understanding of xml manipulation.  I am having difficulty bridging the gap between xml and classic asp, connecting the two, manipulating the xml response and formatting it to any degree of satisfaction.

Let me start here:
1) I have figured out how to format (dynamic string building) and send the xml request to a remote server. VIA "xml.send ReqString"
2) I can correctly (I think) receive the response text (xml) and hold it in a variable.  
3) I can output it via  Response.Write xml.responsetext

Here is where it gets foggy.  There is a lot of documentation that points to the fact that I can use CSS, XSLT, and a few other ways to format it as html.  Which is best for a Microsoft boy? I mean VB VBscript, asp, SQL etc..   I am not remotely afraid of JavaScript but, I would prefer to know how to manipulate it in a classic asp world first.

Just a comment ***
Also, what is this DTD thing all about?  If I know how the request is supposed to go out and format my request correctly, and the response never changes except for the actual encapsulated data.  Why should I really care?   Forgive my blunt crudeness with respect to the founders and Guru's of xml :-)   ok, Data Type Definition.  except we're not in the traditional database table setup right?  Instead of varchar 50 we are saying:
<Stateofmind>
<currently>confused</currently>
</Stateofmind>
LOL

 If I know what I am sending and I know how the response will be formatted, all I need to know is how to clean the response up and do what I want with it right(overhead not included)?  I understand that  XML is badass to a great extent,  and I think I will learn how to harness it's power.  That is what I need a kick start with.  Most of the documentation in books and on the web, is based off of static xml files.  When they actually get dynamic, they end it at here's the xml response. What do you think the response looks like?  It looks like the cute little tree that most of us have seen about a few hundred times when we started researching xml.   Most tutorials end it there.    That does me and I'm sure many other potential XML'ers absolutely no good.  Who the heck is static these days anyway? **

So here is the skinny:
I send a request and I get a response.  The response doesn't have reference to xslt , css,  (DTD maybe) or whatever.  It looks like a static xml file that you see in every tutorial on the planet, but it is not.  I notice that when formatting/ converting xml to html there are references to the style sheets intertwined in the xml.  Also, what's this works in IE and MAYBE other browsers thing?  Wouldn't I want the formatting and manipulation to occur on the server if that is the case?  Who the heck would want to output something that maybe sometimes people can view it?  I would want to know exactly how my server was pushing out responses to an end user. Right?

Anyway before you ask me for example responses and requests, I am working on modifying some to show you.  They are ip secured, so I can't really post the code because it won't work outside of specific addresses.

I am done ranting and raving.  Thanks for any reasonable efforts.  I am feeling a bit disconnected and behind in the times!
Frank
0
Comment
Question by:framos1
  • 8
  • 5
13 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12095321
Okay, a few links and then an example.

http://www.w3schools.com/xml/default.asp
http://www.topxml.com/

Now, if you want to make sure that what you have will work on most every browser, then you will want to make sure that  you do all of the manipulations server side rather than client side. That way, only pure html is sent to the browser, so you are no longer limited to IE.

Example 1--display XML contents through a style sheet and .asp page:

*************
datacontent.xml
*************

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="DataContent.xsl"?>
<DataContent>
  <person>
    <name>Sam the Clam</name>
    <detail>Sea Dweller</detail>
    <age>39</age>
  </person>
  <person>
    <name>Fred the Fish</name>
    <detail>Sea Dweller</detail>
    <age>18</age>
  </person>
</DataContent>

*************
datacontent.xsl
*************
<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">
  <html>
  <body>
    <h2>Data Content Display</h2>
    <table border="0" cellspacing="2">
    <tr bgcolor="gray">
      <th align="left" width="100">Name</th>
      <th align="left" width="150">Detail</th>      
        <th align="left" width="50">Age</th>
    </tr>
    <xsl:for-each select="DataContent/person">
    <tr>
      <td><xsl:value-of select="name"/></td>
      <td><xsl:value-of select="detail"/></td>      
        <td><xsl:value-of select="age"/></td>
    </tr>
    </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template></xsl:stylesheet>

************
datacontent.asp
************

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
  sourceFile = Server.MapPath("DataContent.xml")
  styleFile = Server.MapPath("DataContent.xsl")
 
  set source = Server.CreateObject("Microsoft.XMLDOM")
  source.async = false
  source.load(sourceFile)
  set style = Server.CreateObject("Microsoft.XMLDOM")
  style.async = false
  style.load(styleFile)
  Response.Write source.transformNode(style)
%>


So if you just run this asp file with the two files above in the same directory, the magic starts....

FtB
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12095334
Example 2--display XML contents created from a recordset when you don't know what the data will look like:

*************
datacontent2.xml
*************
<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
      xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
      xmlns:rs='urn:schemas-microsoft-com:rowset'
      xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
      <s:ElementType name='row' content='eltOnly' rs:updatable='true'>
            <s:AttributeType name='CompanyName' rs:number='1' rs:nullable='true' rs:maydefer='true' rs:write='true' rs:basetable='Customers'
                   rs:basecolumn='CompanyName'>
                  <s:datatype dt:type='string' dt:maxLength='40'/>
            </s:AttributeType>
            <s:AttributeType name='ContactName' rs:number='2' rs:nullable='true' rs:maydefer='true' rs:write='true' rs:basetable='Customers'
                   rs:basecolumn='ContactName'>
                  <s:datatype dt:type='string' dt:maxLength='30'/>
            </s:AttributeType>
            <s:AttributeType name='Phone' rs:number='3' rs:nullable='true' rs:maydefer='true' rs:write='true' rs:basetable='Customers'
                   rs:basecolumn='Phone'>
                  <s:datatype dt:type='string' dt:maxLength='24'/>
            </s:AttributeType>
            <s:extends type='rs:rowbase'/>
      </s:ElementType>
</s:Schema>
<rs:data>
      <z:row CompanyName='Franchi S.p.A.' ContactName='Paolo Accorti' Phone='011-4988260'/>
      <z:row CompanyName='Frankenversand' ContactName='Peter Franken' Phone='089-0877310'/>
      <z:row CompanyName='Furia Bacalhau e Frutos do Mar' ContactName='Lino Rodriguez ' Phone='(1) 354-2534'/>
      <z:row CompanyName='Galería del gastrónomo' ContactName='Eduardo Saavedra' Phone='(93) 203 4560'/>
      <z:row CompanyName='Godos Cocina Típica' ContactName='José Pedro Freyre' Phone='(95) 555 82 82'/>
      <z:row CompanyName='The Cracker Box' ContactName='Liu Wong' Phone='(406) 555-5834'/>
      <z:row CompanyName='Toms Spezialitäten' ContactName='Karin Josephs' Phone='0251-031259'/>
      <z:row CompanyName='Tortuga Restaurante' ContactName='Miguel Angel Paolino' Phone='(5) 555-2933'/>
      <z:row CompanyName='Tradição Hipermercados' ContactName='Anabela Domingues' Phone='(11) 555-2167'/>
      <z:row CompanyName='Trail&#x27;s Head Gourmet Provisioners' ContactName='Helvetius Nagy' Phone='(206) 555-8257'/>
      <z:row CompanyName='Vaffeljernet' ContactName='Palle Ibsen' Phone='86 21 32 43'/>
      <z:row CompanyName='Victuailles en stock' ContactName='Mary Saveley' Phone='78.32.54.86'/>
      <z:row CompanyName='Vins et alcools Chevalier' ContactName='Paul Henriot' Phone='26.47.15.10'/>
      <z:row CompanyName='Wartian Herkku' ContactName='Pirkko Koskitalo' Phone='981-443655'/>
      <z:row CompanyName='Wellington Importadora' ContactName='Paula Parente' Phone='(14) 555-8122'/>
      <z:row CompanyName='White Clover Markets' ContactName='Karl Jablonski' Phone='(206) 555-4112'/>
      <z:row CompanyName='Wilman Kala' ContactName='Matti Karttunen' Phone='90-224 8858'/>
      <z:row CompanyName='Wolski  Zajazd' ContactName='Zbyszek Piestrzeniewicz' Phone='(26) 642-7012'/>
</rs:data>
</xml>

**********
generic.xsl
**********

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
                    xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
                    xmlns:rs="urn:schemas-microsoft-com:rowset"
                    xmlns:z="#RowsetSchema">
     <xsl:template match="/">
          <html>
               <head>
                    <title>XSL-Formatted ADO Recordset</title>
               </head>
               <body>
                    <font face="Tahoma" size="2">
                         <table border="1" color="BLUE">
                              <tr>
                                   <xsl:for-each select="xml/s:Schema/s:ElementType/s:AttributeType">
                                        <td>
                                             <strong>
                                                  <font color="red" size="2">
                                                       <xsl:value-of select="@name"/>
                                                  </font>
                                             </strong>
                                        </td>
                                   </xsl:for-each>
                              </tr>
                              <xsl:for-each select="xml/rs:data/z:row">
                                   <tr>
                                        <xsl:for-each select="@*">
                                             <td>
                                                  <font color="blue" size="2">
                                                       <xsl:value-of select="."/>
                                                  </font>
                                             </td>
                                        </xsl:for-each>
                                   </tr>
                              </xsl:for-each>
                         </table>
                    </font>
               </body>
          </html>
     </xsl:template>
</xsl:stylesheet>

***************
datacontent2.asp
**************

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
  sourceFile = Server.MapPath("DataContent2.xml")
  styleFile = Server.MapPath("generic.xsl")
  set source = Server.CreateObject("MSXML2.DOMDocument")
  source.async = true
  source.load(sourceFile)
  set style = Server.CreateObject("MSXML2.DOMDocument")
  style.async = false
  style.load(styleFile)
  Response.Write source.transformNode(style)
%>

FtB
0
 

Author Comment

by:framos1
ID: 12097129
Thanks for responding FtB.

That makes sense to me for the most part, I can follow where you are going.  I am having difficulty getting to that point because, I am not sure the best way to manipulate the response from the other/remote server.  Here is how I am connecting.

*******Round trip code******

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%
  Response.Buffer = True
  Dim objXMLHTTP, xml
  Dim ReqString
    ReqString = "<XML_PriceAvailability_Submit><Header>"
    ReqString = ReqString & "<UserName>username here</UserName><Password>password here</Password>"
    ReqString = ReqString & "<TransSetIDCode>1234</TransSetIDCode>"
    ReqString = ReqString & "<TransControlID>12345</TransControlID>"
    ReqString = ReqString & "</Header><Detail><LineInfo><AssignedID>001</AssignedID>"
    ReqString = ReqString & "<RefIDQual>VP</RefIDQual><RefID>dynamic record from my server here</RefID>"
    ReqString = ReqString & "</LineInfo></Detail><Summary><NbrOfSegments>4</NbrOfSegments></Summary>"
    ReqString = ReqString & "</XML_PriceAvailability_Submit>"

      Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP")
            xml.Open "POST", "http://some.server.com:80/xmlservlet", False
            xml.setRequestHeader "Content-Type", "text/xml"
            xml.send ReqString
%>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<%
   '  Response.Write "<h1>The HTML text</h1><xmp>"
    ' Response.Write xml.responsetext
     ' Response.Write "</xmp><p><hr><p><h1>The HTML Output</h1>"

  Response.Write xml.responsetext
%>
<body>
</body>
</html>
<% Set xml = Nothing %>

*******

Now the xml response I get looks like this.

*******
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE XML_PriceAvailability_Response SYSTEM "XML_PriceAvailability_Response.dtd">
<XML_PriceAvailability_Response>
  <Header>  ~~the rest is pretty standard xml response~~

**********
How do I take that response and modify it? I guess in the memory of my server, as a variable?  To get it to become:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="DataContent.xsl"?>

Do I have to actually save every xml response to my server and then use ** sourceFile = Server.MapPath("DataContent.xml")** to reference it?
thx
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12101888
You will have to bear with me as I am pretty new at this as well. You do not need to save the file to the server, but instead you can interrogate xml stored in a variable. However, the syntax is slightly different. I'll see if I can get my hands on it.

FtB
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12101941
Ah, here we go:

objXML.Load "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml"

So this means that the syntax is pretty much the same--the source is a link rather than a file.

FtB
0
 

Author Comment

by:framos1
ID: 12102963
Ok,
Interrogating the variable is where I am at.  I make a minor change to my code and that is where I fall apart.  
I get my response from the remote server.  
I can write it out..
Response.Write xml.responsetext
I can hold it in a variable..
variablename = xml.responsetext

How do I manipulate the xml once I get it into the variable.  
Here is exactly what the response I get looks like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE XML_PriceAvailability_Response SYSTEM "XML_PriceAvailability_Response.dtd">
<XML_PriceAvailability_Response>
<Header>  ......

In order to use css, xsl etc..  Am I going to need to take the xml response in that is contained in the variable, do some VB string cleaning, and rewrite the whole xml response in a variable so that I can add the lines of code that will allow me to reference any style sheets I make?

 
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12103346
I am not sure about that. For more specifics, you may need to make a post in the XML topic area:

http://www.experts-exchange.com/Web/Web_Languages/XML/

FtB
0
 

Author Comment

by:framos1
ID: 12105183
That's cool, I guess I'll have to post in both.  Thanks for trying.  Maybe I'll get lucky.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12105351
Best of luck,

FtB
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12105359
On the bright side, at least, you have gotten a start with transforing xml data through an xsl file and displaying the result in ASP.

FtB
0
 

Author Comment

by:framos1
ID: 12254948
Hi FTB,
Frank again.  I am going to give you the points on this, I really appreciate you trying.  I am still stuck.  I have learned anough to get me going once I can vigure out how to manipulate the response from the remote server.  I am getting errors when I try and replase the header text:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE XML_PriceAvailability_Response SYSTEM "XML_PriceAvailability_Response.dtd">
 with the proper reference to an xsl file.  Which is believe to be the best way to accopmplish my goal.

Any last thoughts? For me I think it is mor of an asp issue at this point.  But any additional XML advise you can offer would be great.

-F
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 500 total points
ID: 12257947
I may be wrong about this, but don't you need both--one to specify the document type and the other the DTD?

FtB
0
 

Author Comment

by:framos1
ID: 12287656
Ok, I am very close to getting this to work for me.  I think I just need a little help figuring out what is wrong with my XSL file.   I found a good link fro explaining how to load it all on the server side. and output it.  I can get the example to run, but not my code.  Check out this link.  http://www.xmlfiles.com/xsl/xsl_server.asp   I CAN get their examples to run on my server, so I know it works.  

Here is the xsl file I created based on the xml file I am using. I can post that also.  Maybe I am missing a reference?

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
      <html>
      <body>
      <table width="100%"  border="1">
  <tr>
    <th scope="col">whse</th>
    <th scope="col">qty</th>
  </tr>
  <xsl:for-each select="XML_Availability_Response/Detail/LineInfo/WhseInfo">
  <tr>
    <td><xsl:value-of select="IDCode"/></td>
    <td><xsl:value-of select="Qty"/></td>
  </tr>
  </xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now