Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Extracing data from XHTML file into another

Reply
Thread Tools

Extracing data from XHTML file into another

 
 
chris_huh
Guest
Posts: n/a
 
      05-26-2009
On May 26, 3:42*pm, Martin Honnen <(E-Mail Removed)> wrote:
> chris_huh wrote:
> > Yeah, i suppose it could be more of an issue with asp. The asp code i
> > use is:

>
> > <%
> > 'Load XML
> > set xml = Server.CreateObject("Microsoft.XMLDOM")
> > xml.async = false
> > xml.load(Server.MapPath("/iraq/index.shtml"))
> > When the Server.MapPath is a .xml file it works ok, but when it is
> > a .shtml file, loading from the actual file itself it just crashes. It
> > could be something wrong with the shtml file (maybe it isn't correct
> > xhtml) or maybe you can't use an shtml file. Thats what i wasn't sure
> > about.

>
> You can check for parse errors with MSXML as follows, put that after the
> load call:
> * *If xml.parseError.errorCode <> 0 Then
> * * *Response.Write xml.parseError.reason
> * *End If
>
> --
>
> * * * * Martin Honnen
> * * * *http://msmvps.com/blogs/martin_honnen/


The asp finally loaded and came back with:

The system cannot locate the resource specified. Error processing
resource 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'.

Which i guess is meaning the line at the top of the xhtml file. Maybe
it can't read taht properly.
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      05-26-2009
chris_huh wrote:

> The asp finally loaded and came back with:
>
> The system cannot locate the resource specified. Error processing
> resource 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'.
>
> Which i guess is meaning the line at the top of the xhtml file. Maybe
> it can't read taht properly.


Dpoes it work when you set
xml.resolveExternals = False
before the load call?

--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/
 
Reply With Quote
 
 
 
 
chris_huh
Guest
Posts: n/a
 
      05-26-2009
On May 26, 4:03*pm, Martin Honnen <(E-Mail Removed)> wrote:
> chris_huh wrote:
> > The asp finally loaded and came back with:

>
> > The system cannot locate the resource specified. Error processing
> > resource 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'.

>
> > Which i guess is meaning the line at the top of the xhtml file. Maybe
> > it can't read taht properly.

>
> Dpoes it work when you set
> * *xml.resolveExternals = False
> before the load call?
>
> --
>
> * * * * Martin Honnen
> * * * *http://msmvps.com/blogs/martin_honnen/


Now it comes back with: The element 'html' is used but not declared in
the DTD/Schema.
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      05-26-2009
chris_huh wrote:

> Now it comes back with: The element 'html' is used but not declared in
> the DTD/Schema.


Add
xml.validateOnParse = False
before the load call.

--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/
 
Reply With Quote
 
chris_huh
Guest
Posts: n/a
 
      05-26-2009
On May 26, 4:46*pm, Martin Honnen <(E-Mail Removed)> wrote:
> chris_huh wrote:
> > Now it comes back with: The element 'html' is used but not declared in
> > the DTD/Schema.

>
> Add
> * *xml.validateOnParse = False
> before the load call.
>
> --
>
> * * * * Martin Honnen
> * * * *http://msmvps.com/blogs/martin_honnen/


I've got the code like this now, and it just procudes a blank page:

<%
'Load XML
set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.validateOnParse = false
xml.resolveExternals = false
xml.load(Server.MapPath("/iraq/index.shtml"))

If xml.parseError.errorCode <> 0 Then
Response.Write xml.parseError.reason
End If

'Load XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("/includes/topstyle.xsl"))

'Transform file
Response.Write(xml.transformNode(xsl))
%>
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      05-26-2009
chris_huh wrote:

> I've got the code like this now, and it just procudes a blank page:
>
> <%
> 'Load XML
> set xml = Server.CreateObject("Microsoft.XMLDOM")
> xml.async = false
> xml.validateOnParse = false
> xml.resolveExternals = false
> xml.load(Server.MapPath("/iraq/index.shtml"))
>
> If xml.parseError.errorCode <> 0 Then
> Response.Write xml.parseError.reason
> End If
>
> 'Load XSL
> set xsl = Server.CreateObject("Microsoft.XMLDOM")
> xsl.async = false
> xsl.load(Server.MapPath("/includes/topstyle.xsl"))
>
> 'Transform file
> Response.Write(xml.transformNode(xsl))
> %>


Well I would first debug the stylesheet in an XML editor to ensure it
produces the output you want before running it in ASP.
If you need help with the stylesheet then you need to share the XML
input and the XSLT stylesheet.

--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/
 
Reply With Quote
 
chris_huh
Guest
Posts: n/a
 
      05-26-2009
On May 26, 5:13*pm, Martin Honnen <(E-Mail Removed)> wrote:
> chris_huh wrote:
> > I've got the code like this now, and it just procudes a blank page:

>
> > <%
> > 'Load XML
> > set xml = Server.CreateObject("Microsoft.XMLDOM")
> > xml.async = false
> > xml.validateOnParse = false
> > xml.resolveExternals = false
> > xml.load(Server.MapPath("/iraq/index.shtml"))

>
> > If xml.parseError.errorCode <> 0 Then
> > Response.Write xml.parseError.reason
> > End If

>
> > 'Load XSL
> > set xsl = Server.CreateObject("Microsoft.XMLDOM")
> > xsl.async = false
> > xsl.load(Server.MapPath("/includes/topstyle.xsl"))

>
> > 'Transform file
> > Response.Write(xml.transformNode(xsl))
> > %>

>
> Well I would first debug the stylesheet in an XML editor to ensure it
> produces the output you want before running it in ASP.
> If you need help with the stylesheet then you need to share the XML
> input and the XSLT stylesheet.
>
> --
>
> * * * * Martin Honnen
> * * * *http://msmvps.com/blogs/martin_honnen/


The asp file is making the correct coding apart from the foreach
stuff.

So at the moment i have this for the ASP:

<%
'Load XML
set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.validateOnParse = false
xml.resolveExternals = false
xml.load(Server.MapPath("/iraq/test.shtml"))

If xml.parseError.errorCode <> 0 Then
Response.Write xml.parseError.reason
End If

'Load XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("/includes/topstyle.xsl"))

'Transform file
Response.Write(xml.transformNode(xsl))
%>

This for the XSL:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform">

<xslutput method="xml" version="1.0" encoding="UTF-8" doctype-
public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/
TR/xhtml11/DTD/xhtml11.dtd" indent="yes"/>

<xsl:template match="/">
<html>
<head>
<title>Test</title>
</head>
<body>
<ul>
<xsl:for-each select="html/body/item">
<li>
<xsl:value-of select="headline" />
</li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

And this for the XHTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN">
<head>

<title>Test stories</title>

</head>

<body class="iraq">

<item>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="226" rowspan="2" valign="top"><a href="#"><img src="../
images/placeholder226.jpg" alt="Story 1" name="Story1image"
width="226" height="170" id="Story1image" /></a></td>
<td width="10" rowspan="2" valign="top"></td>
<td valign="top"><h2 class="itemheader"><a href="#"
class="itemlink"><headline>Story 1 headline</headline></a></h2></td>
</tr>
<tr>
<td valign="top" class="itemdescription">Story 1 summary</td>
</tr>
<tr>
<td height="10" colspan="3" valign="top"></td>
</tr>
</table></item>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="238" align="left" valign="top">
<item>
<table width="228" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="76" valign="top"><a href="#"><img src="../images/
placeholder66.jpg" alt="Story 2" name="Story2image" width="66"
height="49" id="Story2image" /></a></td>
<td valign="top"><h3 class="itemheader"><a href="#"
class="itemlink"><headline>Story 2 headline</headline></a></h3></td>
</tr>
<tr>
<td colspan="2" valign="top" height="10"></td>
</tr>
<tr>
<td colspan="2" valign="top" class="itemdescription">Story 2
summary</td>
</tr>
</table></item></td>
<td align="right" valign="top"><item><table width="228" border="0"
cellspacing="0" cellpadding="0">
<tr>
<td width="76" valign="top"><a href="#"><img src="../images/
placeholder66.jpg" alt="Story 3" name="Story3image" width="66"
height="49" id="Story2image2" /></a></td>
<td valign="top"><h3 class="itemheader"><a href="#"
class="itemlink"><headline>Story 3 headline</headline></a></h3></td>
</tr>
<tr>
<td colspan="2" valign="top" height="10"></td>
</tr>
<tr>
<td colspan="2" valign="top" class="itemdescription">Story 3
summary</td>
</tr>
</table></item></td>
</tr>
</table>


</body>

</html>

Obviously i want to change the XHTML to look nicer but i am just
trying to get this working. I know the ASP and XSL work because if i
use an XML file instead of XHTML it works:

<?xml version="1.0" encoding="ISO-8859-1"?>
<news>
<item><headline>Story 1 headline</headline></item>
<item><headline>Story 2 headline</headline></item>
<item><headline>Story 3 headline</headline></item>
</news>
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      05-26-2009
chris_huh wrote:

> <xsl:stylesheet version="1.0"
> xmlnssl="http://www.w3.org/1999/XSL/Transform">


You need
xmlns="http://www.w3.org/1999/xhtml"
xmlnshtml="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xhtml"
here on the xsl:stylesheet element to access XHTML elements and to
create XHTML elements.


> <xsl:template match="/">
> <html>
> <head>
> <title>Test</title>
> </head>
> <body>
> <ul>
> <xsl:for-each select="html/body/item">


You need to qualify all element names with the prefix 'xhtml' I defined
above e.g.
select="xhtml:html/xhtml:body/xhtml:item"

> <li>
> <xsl:value-of select="headline" />


Same here
select="xhtml:headline"

and so one everywhere you want to access or match elements from the
source document.



--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/
 
Reply With Quote
 
chris_huh
Guest
Posts: n/a
 
      05-26-2009
On May 26, 5:45*pm, Martin Honnen <(E-Mail Removed)> wrote:
> chris_huh wrote:
> > <xsl:stylesheet version="1.0"
> > xmlnssl="http://www.w3.org/1999/XSL/Transform">

>
> You need
> * *xmlns="http://www.w3.org/1999/xhtml"
> * *xmlnshtml="http://www.w3.org/1999/xhtml"
> * *exclude-result-prefixes="xhtml"
> here on the xsl:stylesheet element to access XHTML elements and to
> create XHTML elements.
>
> > <xsl:template match="/">
> > <html>
> > <head>
> > <title>Test</title>
> > </head>
> > <body>
> > * <ul>
> > * * <xsl:for-each select="html/body/item">

>
> You need to qualify all element names with the prefix 'xhtml' I defined
> above e.g.
> * * * * * * * * * * *select="xhtml:html/xhtml:body/xhtml:item"
>
> > * * <li>
> > * * * <xsl:value-of select="headline" />

>
> Same here
> * * * * * * * * * * * *select="xhtml:headline"
>
> and so one everywhere you want to access or match elements from the
> source document.
>
> --
>
> * * * * Martin Honnen
> * * * *http://msmvps.com/blogs/martin_honnen/


Now i have the xsl like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlnshtml="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xhtml" >

<xslutput method="xml" version="1.0" encoding="UTF-8" doctype-
public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/
TR/xhtml11/DTD/xhtml11.dtd" indent="yes"/>

<xsl:template match="/">
<html>
<head>
<title>Test</title>
</head>
<body>
<ul>
<xsl:for-each select="xhtml:html/xhtml:body/xhtml:item">
<li>
<xsl:value-of select="xhtml:headline" />
</li>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

which works a bit better (the Li items show up) but there still isn't
anything inside the li items.
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      05-26-2009
chris_huh wrote:

> <xsl:for-each select="xhtml:html/xhtml:body/xhtml:item">
> <li>
> <xsl:value-of select="xhtml:headline" />


I think those headline elements are deep down inside the table so you
either have to spell out the complete path or use
<xsl:value-of select="descendant:html:headline"/>

--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert xhtml to another xhtml using xslt Usha2009 XML 0 12-20-2009 01:13 PM
Extracing data from webpage srinivasan srinivas Python 2 09-11-2008 12:00 PM
Linux, extracing symbol table to read core dump Johannes Bauer C Programming 2 11-08-2007 06:01 PM
extracing .PAC archives Travis Computer Information 2 07-17-2007 08:22 AM
VHDL and extracing equations buke2 VHDL 2 07-28-2004 02:14 PM



Advertisments