Google Answers Logo
View Question
 
Q: xml to multiple html documents ( No Answer,   4 Comments )
Question  
Subject: xml to multiple html documents
Category: Computers
Asked by: getlocal-ga
List Price: $20.00
Posted: 10 Dec 2005 10:01 PST
Expires: 09 Jan 2006 10:01 PST
Question ID: 604099
I am looking for a servlet or just a  simple java program(script) that
can convert objects in an xml document into seperate  and static html
documents, for example:
http://www.getboca.com/test/boca_raton.xml
using a bare bones style sheet like  
http://www.getboca.com/test/boca_raton.xsl

I would like a script that can convert each ID object into it's own
static html document.

Request for Question Clarification by answerguru-ga on 10 Dec 2005 12:20 PST
Hi there,

Can you provide a sample of what the individual HTML documents should
look like and how they should be named?

Thanks,
answerguru-ga

Clarification of Question by getlocal-ga on 10 Dec 2005 19:04 PST
Hello, 

In regards to the layout and style of the individual HTML documents-
at the time being something as simple as:

<-----------------------   local.css   ---------------------->

#div {
      text-align: center;
      margin-right: auto;
      margin-left: auto;
      border: solid;
      margin-top: 20%; 
      color: #000000;
      }

.name {
        font-size: 30pt; 
        font-weight: boldest;
        color: red;
        }
.type {
        font-size; 15pt;
        } 
.address {
           font-size: 12pt;
          }
.phone {
         font-size:12pt;
         font-weight: bold;
        }

<---------------- -------------------->

<------------------ HTML doc ------------------->

<html>
<head>
<title>getlocal</title>
<link rel="stylesheet" type="text/css" href="local.css" />
</head>
<body>
<div id="div">
<span class="name">@</span>
<span class="type">@</span>
<span class="address">@</span>
<span class="phone">@</span>
</div>
</body>
</html>

<---------------------------------         --------------------->

In response to your question about naming the documents- using the
objects ID would be sufficient for the time being.

Many thanks,

Mark Stepanek

Request for Question Clarification by answerguru-ga on 11 Dec 2005 00:48 PST
Hi Mark,

I've had a look at your requirement and haven't had any luck finding
something that exists already that does this. I can write a Java
application that can be run from the command line which accomplishes
what you want, though the cost for this would be in the $200 range.

Are you familiar with how to compile and execute java source code?

Let me know how you would like to proceed.

answerguru-ga

Clarification of Question by getlocal-ga on 11 Dec 2005 09:04 PST
I am familiar with how to compile and execute java source code,
however I cannot afford to pay $200 at the time. I hope I didn't waste
too much of your time.

Thanks again,

Mark

Request for Question Clarification by answerguru-ga on 11 Dec 2005 09:09 PST
Not a problem at all - other researchers are free to address this question.

Cheers,
answerguru-ga
Answer  
There is no answer at this time.

Comments  
Subject: Re: xml to multiple html documents
From: astrochicken-ga on 15 Dec 2005 21:31 PST
 
Download the necessary libraries (dom4j.jar & jaxen.jar) from
dom4j.org and compile the following...

-- SoItWorks.java ----------------------------
import java.io.FileOutputStream;
import java.util.Iterator;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Node;
import org.dom4j.io.DocumentResult;
import org.dom4j.io.DocumentSource;
import org.dom4j.io.HTMLWriter;
import org.dom4j.io.SAXReader;
import org.dom4j.tree.DefaultElement;

public class SoItWorks {
  
  public static void main(String[] args) throws Exception {
    
    Document xmlDoc;
    xmlDoc = new SAXReader().read("boca_raton.xml");
    
    for (Iterator it = xmlDoc.selectNodes("Import/Row").iterator();
it.hasNext(); ) {
      Node xmlNode;
      xmlNode = (Node) it.next();
      xmlNode.detach();
  
      // stylesheet workaround
      Document dummyDoc;
      dummyDoc = DocumentHelper.createDocument(new DefaultElement("Import"));
      dummyDoc.getRootElement().add(xmlNode);
      
      // load the transformer using JAXP
      TransformerFactory factory;
      factory = TransformerFactory.newInstance();
      
      Transformer transformer;
      transformer = factory.newTransformer( 
          new StreamSource("boca_raton.xsl") 
      );
  
      // now lets style the given document
      DocumentSource source = new DocumentSource(dummyDoc);
      DocumentResult result = new DocumentResult();
      transformer.transform( source, result );
  
      // write the transformed document
      Document styledDoc;
      styledDoc = result.getDocument();
      
      HTMLWriter htmlWriter;
      htmlWriter = new HTMLWriter(new
FileOutputStream(xmlNode.valueOf("Id") + ".html"));
      htmlWriter.write(styledDoc);
    }
  }
}
Subject: Re: xml to multiple html documents
From: getlocal-ga on 19 Dec 2005 11:44 PST
 
When you stated that other researchers are free to address my
question, were you implying that if I repost the question it may be
discovered by another researcher who may have a solution that better
fits my budget? I do not want to use up too much of researchers time
asking how I could get a dollar from 15 pennies if my budget is too
small for my request.
Subject: Re: xml to multiple html documents
From: getlocal-ga on 01 Jan 2006 12:51 PST
 
THANK YOU! Happy New Year!
Subject: Re: xml to multiple html documents
From: getlocal-ga on 05 Jan 2006 01:40 PST
 
Thank you for answering my question PERFECTLY! I downloaded the jar's
and the program you provided me worked beautifully. The answer status
is 'needs attention'. How much do I owe you for your services? You met
and exceeded my expectations(I would have struggled for some time on
the library issue had you not informed me to get the right jar files.
Thank You, Mark Stepanek

p.s. Would it be reasonable to work with google answers on a much
larger web application? ie an application that for each id in the
boca_raton.xml file created a dynamic, scalable, and user customizable
web. The general idea being to have a prebuilt page for every business
for which the owner could add content to and customize to a small
degree. I'm sure it would be thousands of dollars, could you give me
an idea of how many thousands?

If this is another question I am willing to pay this questioned answered as well.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy