• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 713
  • Last Modified:

Print .xml document....ASP

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
akbiro
Asked:
akbiro
  • 9
  • 5
1 Solution
 
Rajar AhmedConsultantCommented:
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
 
mcuk_stormCommented:
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
 
akbiroAuthor Commented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mcuk_stormCommented:
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
 
akbiroAuthor Commented:
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
 
akbiroAuthor Commented:
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
 
mcuk_stormCommented:
What link are you referring to?
0
 
akbiroAuthor Commented:
0
 
mcuk_stormCommented:
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
 
akbiroAuthor Commented:
OK...I understand...sorry for the mistake....thanks!!!
0
 
akbiroAuthor Commented:
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
 
akbiroAuthor Commented:
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
 
mcuk_stormCommented:
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
 
akbiroAuthor Commented:
Ok...this helps...
0
 
akbiroAuthor Commented:
If I have more questions I will open a new incident...you can keep an eye out for me please.  THANKS
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now