Solved

Print .xml document....ASP

Posted on 2010-08-22
15
677 Views
Last Modified: 2012-05-10
Are there any simple templates to demonstrate reading an .xml file, grouping certain records together and printing them out?  I have an inventory file that I want to print in format layout.  I do not want to do this with PHP.  ASP would be great.
0
Comment
Question by:akbiro
  • 9
  • 5
15 Comments
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 33495428
try this ..
Reference URL
http://www.stardeveloper.com/articles/display.html?article=2000072801&page=1
<%
Option Explicit
Response.Buffer = True

Dim xml
	Set xml = Server.CreateObject("Microsoft.XMLDOM")
	xml.async = False
	xml.load (Server.MapPath("xml/pageview.xml"))

Dim title, heading, paragraph, testHTML
	title = xml.documentElement.childNodes(0).text
	heading = xml.documentElement.childNodes(1).text
	paragraph = xml.documentElement.childNodes(2).text
	testHTML = xml.documentElement.childNodes(3).text

	Set xml = Nothing
%>
<html>
<head>
	<title><%= title %></title>
</head>
<body>
<h3 align="center"><%= heading %></h3>
<p align="center"><% = paragraph %></p>
<div align="center"><%= testHTML %></div>
</body>
</html>
<!--ASPFILE ENDS-->
-----------------------------------------
PAGEVIEW XML FILE Starts
----------------------------------------
<?xml version="1.0" encoding="iso-8859-1"?>
<main>
 <title>Our Page.xml file</title>
 <heading>This is a test heading</heading>
 <paragraph>This is our paragraph and you can write whatever 
  you want to in this space.</paragraph>
  <testHTML><![CDATA[We will enclose some HTML code in CDATA section now :<br>
 <table width="60%" border="1" bordercolor="silver" cellspacing="2" 
      cellpadding="3">
    <tr>
     <td>
      You can write any HTML code or for that matter any type of text inside 
      the CDATA section without a fear of getting any error.<br><br>
      Note if we write this without the CDATA tags, the xml parser will 
      raise an error and won't show the document.
     </td>
    </tr>
   </table>]]></testHTML>
  </main>

Open in new window

0
 
LVL 7

Expert Comment

by:mcuk_storm
ID: 33495432
Are you looking for a classic ASP/VBScript solution or an ASP.NET/VB/C# solution? Also what do you mean by grouping records together, could you give an extract of the expected input data and how you would expect it to be output.
0
 

Author Comment

by:akbiro
ID: 33495551
I think this is a difficult project...I may be wishing for too much at my level of programing skills...I am a cut and paster...I find someone else work and try to copy can change it.  Slowly, I am learning more and more.  With that said, my .xml inventory file has a hide file (true or null).  If the item is true then I do not want the item in my print document, if it is null, then I do.  I want to group the inventory in alphabetical order by category and columns forscientific and common names, and three prices under each available size.  If there is no information for a size, I want to display, N/A.  How hard will this be to do?


THANKS for looking and helping.
printPriceTemplate.xlsx
products.xml
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 7

Accepted Solution

by:
mcuk_storm earned 500 total points
ID: 33495884
I'll leave the formatting to you, but the attached files should get you well on your way, in summary it will:
Load an XSLT (XML transformation sheet) and apply it against the HTML to sort the items by category,
It will then select all nodes that don't have hide set to true
It will then loop through each of these output category headings as they change and list upto 3 items per category.

The code below is for the .asp file, the attached file is the XSL sheet. You will likely need to change the paths to the XSL & XML documents these are set in the asp on lines 5(XSL), 13(XML) if they are in the webroot then leave the Server.MapPath in as this tells it to find the actual path based on its location in the webserver root directory. If they are not in the webroot then take out the server.mappath and put the full path in the quotes (i.e. "c:\inetpub\data\test.xml")

<%
Dim objXSLT : Set objXSLT = Server.CreateObject("Msxml2.DOMDocument.6.0")
objXSLT.ASync = False
objXSLT.setProperty "SelectionLanguage","XPath"
If Not objXSLT.Load(Server.MapPath("/Q26420449/sort.xsl")) Then
	Response.Write "Error loading XSLT: " & objXSLT.parseError.reason
	Response.End
End If

Dim objXML : Set objXML = Server.CreateObject("Msxml2.DOMDocument.6.0")
objXML.ASync = False
objXML.setProperty "SelectionLanguage","XPath"
If Not objXML.Load(Server.MapPath("/Q26420449/src.xml")) Then
	Response.Write "Error loading XML: " & objXML.parseError.reason
	Response.End
End If

strSortedXML = objXML.transformNode(objXSLT)
If Not objXML.LoadXML(strSortedXML) Then
	Response.Write "Error loading XML: " & objXML.parseError.reason
	Response.End
End If


Dim dictCats : Set dictCats = Server.CreateObject("Scripting.Dictionary")

Set objResults = objXML.selectNodes("//row[hide!='true']")
If objResults.length > 0 Then
	Dim objNode, objSubNode, strCurrentCat, intCatCount
	strCurrentCat = ""
	intCatCount = 0
	Do
		Set objNode = objResults.nextNode()
		If objNode Is Nothing Then Exit Do
		
		Set objSubNode = objNode.selectSingleNode("category")
		If Not objSubNode Is Nothing Then
			If Not strCurrentCat = LCase(objSubNode.text) Then
				intCatCount = 0
				strCurrentCat = LCase(objSubNode.text)
				Response.Write "<h2>" & strCurrentCat & "</h2>"
			End If
			
			intCatCount = intCatCount + 1
			If intCatCount < 4 Then
				strNodeName = "pname" : Response.Write strNodeName & ": " & getNodeValue(objNode.selectSingleNode(strNodeName)) & "<br />"
				strNodeName = "psubname" : Response.Write strNodeName & ": " & getNodeValue(objNode.selectSingleNode(strNodeName)) & "<br />"
				strNodeName = "lprice1" : Response.Write strNodeName & ": " & getNodeValue(objNode.selectSingleNode(strNodeName)) & "<br />"
				strNodeName = "lprice2" : Response.Write strNodeName & ": " & getNodeValue(objNode.selectSingleNode(strNodeName)) & "<br />"
				strNodeName = "lprice3" : Response.Write strNodeName & ": " & getNodeValue(objNode.selectSingleNode(strNodeName)) & "<br />"
				strNodeName = "mprice1" : Response.Write strNodeName & ": " & getNodeValue(objNode.selectSingleNode(strNodeName)) & "<br />"
				strNodeName = "mprice2" : Response.Write strNodeName & ": " & getNodeValue(objNode.selectSingleNode(strNodeName)) & "<br />"
				strNodeName = "mprice3" : Response.Write strNodeName & ": " & getNodeValue(objNode.selectSingleNode(strNodeName)) & "<br />"
				strNodeName = "sprice1" : Response.Write strNodeName & ": " & getNodeValue(objNode.selectSingleNode(strNodeName)) & "<br />"
				strNodeName = "sprice2" : Response.Write strNodeName & ": " & getNodeValue(objNode.selectSingleNode(strNodeName)) & "<br />"
				strNodeName = "sprice3" : Response.Write strNodeName & ": " & getNodeValue(objNode.selectSingleNode(strNodeName)) & "<br />"
				Response.Write "<hr />"
			End If
			
		End If
		
	Loop
	
End If

Function getNodeValue(objNode)
	If Not objNode Is Nothing Then
		getNodeValue=objNode.text
	Else
		getNodeValue=""
	End if
End Function

Response.Write TypeName(objResults)

Set objResults = Nothing
Set objXML = Nothing
%>

Open in new window

sort.xsl
0
 

Author Comment

by:akbiro
ID: 33496134
Wow...are you kidding me...this is WONDERFUL...give me a little time to put it all together and I'll be back.  Thank you and thank you again...I am excited!!
0
 

Author Comment

by:akbiro
ID: 33496472
Can you look at the link and tell me if I have made a mistake with the location of product.xml.  For testing purposes I have placed a copy of the xml file same file as the .asp and xsl.  Paths always mess me up.
0
 
LVL 7

Expert Comment

by:mcuk_storm
ID: 33496490
What link are you referring to?
0
 

Author Comment

by:akbiro
ID: 33496508
0
 
LVL 7

Expert Comment

by:mcuk_storm
ID: 33496534
the case of the tag names is different to that you posted as the example data, i.e. where in the example xml there was a tag called pname in the one you are using at the moment it is pName you should just need to change the tag names in the code provided to match the case of your XML and it should be ok. It is mostly working at the moment, it is finding and displaying the categories and the products, it just cant find the information for the products because when it tries to find a tag it is looking in a case sensitive manner.
0
 

Author Comment

by:akbiro
ID: 33496540
OK...I understand...sorry for the mistake....thanks!!!
0
 

Author Closing Comment

by:akbiro
ID: 33496551
This was just wonderful and I really can't begin to tell you how much it is appreciated.  I hope you will keep an eye out for my questions in the future.  Have a great day...Andy
0
 

Author Comment

by:akbiro
ID: 33499555
I hate to ask you more, but I have no clue how to format this.  I do NOT want you to do the work, but if you could send me a template or example of the way you might place the information in tables or use CSS it would be gratefully appreciated!!!
0
 
LVL 7

Expert Comment

by:mcuk_storm
ID: 33503420
before the example code if you start the table:
<table>
<% ....

then where it currently outputs an <h2> tag you can change this to output a table row with one table heading spanning all the way across, then the heading for Large,Medium,Small in a new row:
Response.Write "<tr><th colspan=""12"">" & strCurrentCat & "</th></tr>"
Response.Write "<tr><th></th><th colspan=""2""></th><th colspan=""2"">Large</th><th colspan=""2"">Medium</th><th colspan=""2"">Small</th></tr>"

Then where it outputs the items change this to output a table row:
Response.Write "<tr><td></td>"
strNodeName = "pname" : Response.Write "<td>" & getNodeValue(objNode.selectSingleNode(strNodeName)) & "</td>"
...
...


Then at the very end after %> add
</table>
0
 

Author Comment

by:akbiro
ID: 33503448
Ok...this helps...
0
 

Author Comment

by:akbiro
ID: 33503459
If I have more questions I will open a new incident...you can keep an eye out for me please.  THANKS
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Powershell script to zip up xml files in a directory 13 26
Writing comments on <p></P> or paragraph 2 19
key press alert 2 32
xslt 1.0 - How to split value 8 23
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

790 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