Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Location: http://www.jguru.com/faq/XML
Ownership: http://www.jguru.com/misc/user-agree.jsp#ownership.
What is XML?
Location: http://www.jguru.com/faq/view.jsp?EID=1092
Created: Nov 16, 1999
Author: Bruce Martin (http://www.jguru.com/guru/viewbio.jsp?EID=12)
XML, on the other hand, is extensible. It allows the document author to define his
own tags and assign meaning to them. The part of the XML document that
accomplishes this is the Document Type Declaration (DTD). The DTD consists of a
formal definition of the document type. It assigns names for element types and
describes the valid syntax of the document.
XML is being standardized by the XML Working Group of the World Wide Web
Consortium (W3C). The specification for Version 1.0 was accepted by the W3C on
Feb 10, 1998.
XML is good for representing data in a vendor neutral format. It is a good format for
exchanging data between software systems. It separates the content of the data
from the presentation of it.
It seems like almost every kind human endeavor has some kind of group that is
standardizing on DTDs that are relevant to them. By defining DTDs, they are able to
exchange tagged data. The tags represent something about the semantics of the
data. Often they name the resulting language defined by the standard DTD as
something-ML. For example, a group defining exchange of real estate data (listings
of houses, vacation properties, etc.) defined some DTDs and called the resulting
language relML.
The DOM stands for the Document Object Model. It defines a programmatic API for
accessing XML documents. The XML document is represented as a tree. Using the
DOM API, a programmer can construct, query, traverse and manipulate XML
documents programmatically.
XML parsers consume XML documents and then typically produce trees that can be
accessed using the DOM API.
IBM's Alphaworks site has XML parsers written in Java and C++. Both produce DOM
trees.
Sun's project X also has an XML parser written in Java. It produces a DOM trees.
The DOM is actually specified in a language independent fashion using OMG IDL.
Thus, in theory any language for which there is an IDL binding could be supported.
In practice, Java is the most popular language for accessing XML documents using
the DOM.
Xbeans are Java Beans. Java Bean technology supports the packaging, reuse,
connection and customization of Java code. With the appropriate set of Xbeans and a
Java Bean design tool, it is possible to build useful distributed applications with little
or no programming! See the white paper "Creating Distributed Applications Using
Xbeans" for a more detailed discussion of Xbeans and applications that use them.
The Cascading Stylesheet Specification (CSS) is a language for associating styles and
elements. Cascading Stylesheets have been used in browsers with HTML. Microsoft
Internet Explorer 5 also uses cascading style sheets with XML.
The Extensible Style Language (XSL) was designed to be used with XML. XSL is
described in XML. That is, a style sheet is just and XML file.
If you include a namespace in the root element of your source document, a spec-
compliant XSLT processor is supposed to duplicate it into the resulting document.
This is often not what you want. To get rid of it, there's an attribute you can include
in the XSL stylesheet:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:pp="http://medwired.com/namespaces/practiceportal/1.0"
xmlns:xlink='http://www.w3.org/XML/XLink/0.9'
exclude-result-prefixes="pp xlink"
>
Sun manages the XML-INTEREST list. You can signup and read the archives at
http://archives.java.sun.com/archives/xml-interest.html.
There are also the Apache XML mailing lists. See http://xml.apache.org/mail.html.
How can I convert the .txt files to xml document? Are there any reliable
softwares available, or can I do it with the help of Java?
Location: http://www.jguru.com/faq/view.jsp?EID=11615
Created: Feb 4, 2000 Modified: 2000-02-09 21:39:35.666
Author: Bruce Martin (http://www.jguru.com/guru/viewbio.jsp?EID=12)
Windows .txt files are files that contain human readable ascii text. There is no further
structure to it. XML files are also human readable but reflect natural structure in the
file's data. Unfortunately, there is no magic. You need to understand the format of
the data in your text files, define a DTD to reflect that structure and then represent
the data in your .txt files in XML.
Comments and alternative answers
http://bobcat.webappcabaret.net/javachina/faq/xml_java_01.htm#jaxp_sax_Q05
According to Sun, it's impossible to write a DTD for JSP because it's not XML-
complient. It cannot even be called 100% derived from SGML. But, you may use a
non-validating XML parser to parse JSP - just set DTD to null, or use non-validating
parser that doesn't use DTD at all.
Comments and alternative answers
There is an alternative XML compliant syntax for JSP which is not often used. You
can find an article describing its use here
http://www.onjava.com/pub/a/onjava/2001/11/28/jsp_xml.html. It conforms to a
specific DTD found here http://java.sun.com/dtd/jspxml.dtd or XML Schema here
http://java.sun.com/dtd/jspxml.xsd
Are there any commerical tools, with a Java API, that would allow dynamic
PDF document generation?
Location: http://www.jguru.com/faq/view.jsp?EID=23945
Created: Mar 14, 2000 Modified: 2000-03-16 23:17:38.248
Author: Jérôme Bernard (http://www.jguru.com/guru/viewbio.jsp?EID=23090)
Question originally posed by Gary Moh
(http://www.jguru.com/guru/viewbio.jsp?EID=23320
It seems that there is no commercial packages but however, there are many free
ones. Here is a short list of these tools:
• http://www.lowagie.com/iText/
• http://www.retep.org.uk/pdf/
• http://www.etymon.com/pj (this one offers consulting services)
• http://xml.apache.org/fop/ (the well-known XML to PDF generator)
http://www-4.ibm.com/software/developer/education/...
Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7), Jun 20,
2000
http://www-4.ibm.com/software/developer/education/transforming-
xml/xmltopdf/index.html also describes the process of converting an XML file to
PDF.
XML to PDF
Author: Bruno Lowagie (http://www.jguru.com/guru/viewbio.jsp?EID=492448),
Sep 7, 2001
iText is able to do XML to PDF conversion too.
Take a look at the Chap07xx examples at this URL:
http://www.lowagie.com/iText/examples/
Re: http://www-4.ibm.com/software/developer/education/...
Author: Sean O'Leary (http://www.jguru.com/guru/viewbio.jsp?EID=862615),
May 1, 2002
another nice package is at www.xmlpdf.com
Commercial Tool
Author: Joshua Aversa (http://www.jguru.com/guru/viewbio.jsp?EID=842794), Apr
17, 2002
I know of one commercial tool sold by http://www.sitraka.com/ (formaly klgroup).
They sell JClass DesktopViews and JClass ServerViews. In DesktopViews they have
a PageLayout component that allows client side creation of PDFs and in ServerViews
they have a ServerReport that generates PDFs from a server.
Look at the online APPLET demo that lets you get the test of PDF generation
online and instantly.
How can I prevent text that contains "" or ">" from interfering with
parsing. Are there other characters I need to be concerned about?
Location: http://www.jguru.com/faq/view.jsp?EID=24552
Created: Mar 15, 2000 Modified: 2000-04-04 11:44:06.728
Author: Robert Quinn (http://www.jguru.com/guru/viewbio.jsp?EID=18022)
Question originally posed by Robert Quinn
(http://www.jguru.com/guru/viewbio.jsp?EID=18022
Is there any other way to declare a schema for XML other than DTD's ?
Location: http://www.jguru.com/faq/view.jsp?EID=30438
Created: Mar 30, 2000 Modified: 2000-04-04 12:38:18.174
Author: Seok-jeong Hwang (http://www.jguru.com/guru/viewbio.jsp?EID=30431)
Question originally posed by Anil Punjabi
(http://www.jguru.com/guru/viewbio.jsp?EID=23218
There are many proposals for describing xml schema but none have reached the
point that they are in products.
• XML-Data
• DCD.
• DDML.
What is XSLT?
Location: http://www.jguru.com/faq/view.jsp?EID=31864
Created: Apr 4, 2000 Modified: 2000-12-03 20:12:42.776
Author: Thijs Stalenhoef (http://www.jguru.com/guru/viewbio.jsp?EID=31863)
Question originally posed by Gaurav Marballi
(http://www.jguru.com/guru/viewbio.jsp?EID=5750
XSLT is the part of XSL used to transform XML documents to HTML, PDF etc. or other
XML documents. It can help you publish an XML document in a variety of formats.
For instance, it can be used to convert an XML document in a data format used by a
particular company to the XML data format used by another company.
(From Mathew Cobby) XML is purely "data about data". i.e. there is no concept of
HOW something should look, it might not even have a visual representation. XML is
about shoving data around and then doing something application specific with it.
DHTML is about creating pages and how they should look (and behave). In XML there
is no concept of a page, just nodes of data. XML is really a backend tool while DHTML
is more of a front end tool.
(From Thijs Stalenhoef) It is tempting to compare HTML to XML, but they are in fact
two quite different beasts which both share the same ancestor, namely SGML
(Standard Generalized Markup Language). HTML gives data a certain look. XML on
the other hand gives data meaning. XML documents say nothing about how the data
they include should be represented. That is up to other systems such as XSL that can
convert XML documents to (amongst other things) HTML.
Simple example: say you are building a website that will contain a lot of books. in
HTML you could do something like:
XML What's it all about
Price: $25.45
Available: Yes
This will give you 4 lines of text about the book. In XML you would do something
similar:
<Book Available="yes">
<Title>XML What's it all about</Title>
<Author>N.B. Inparticular</Author>
<Price>$25.45</Price>
</Book>
The same essential information is present, only in XML is because really easy for an
automated system to detect the structure of the document and for instance store it
in a database or convert it to HTML, PDF or something else. Check out the XML
tutorials on www.webmonkey.com for a slightly more in depth discussion of XML and
what it means. The book "The XML Handbook" published by Prentice Hall is very
good material also.
or as
<ORDER>
<ITEM>XXXX</ITEM>
<QTY>10</QTY>
<UNIT>PC</UNIT>
</ORDER>
Location: http://www.jguru.com/faq/view.jsp?EID=31906
Created: Apr 4, 2000 Modified: 2000-04-28 14:18:52.053
Author: Thijs Stalenhoef (http://www.jguru.com/guru/viewbio.jsp?EID=31863)
Question originally posed by Nilesh Shah
(http://www.jguru.com/guru/viewbio.jsp?EID=1810
(From Thijs Stalenhoef) Although technically the above two orders are the same
there are a couple of things you might want to consider.
Elements can contain other elements, attributes do not have this kind of functionality
(i.e. their content has no explicit structure). So if you want to replace for instance
content between <UNIT> and </UNIT> with something more complex then "PC" (for
instance something containing further XML tags!) you'll run into trouble with the first
implementation. Ordering is another thing.
Attributes may only appear once in an element and their order may be completely
random. Elements however must always appear in the same order and can occur as
often as you like (or as your schema/DTD says they can occur).
Ways to think about attributes are as data that is of lesser importance, meta-data or
properties. You are free to implement elements and attributes as you see fit. There
are no real rules. Just keep the above in mind when setting up an XML document.
• elements are that elements make your design easier to extend than attributes
• It is difficult to model complex structures using attributes
• the attribute support is not uniform amongst parsers
• elements can be enforced by a DTD
[Updated Nov 20, 2002 to remove old description and point at some articles. TJP]
jGuru.com Case-Study.
Can I use WML (wireless markup language) from a Java Server Page?
Location: http://www.jguru.com/faq/view.jsp?EID=35988
Created: Apr 13, 2000 Modified: 2000-05-12 08:13:30.136
Author: Shaun Childers (http://www.jguru.com/guru/viewbio.jsp?EID=30243)
Question originally posed by RAMESH NIMMAKAYALA
(http://www.jguru.com/guru/viewbio.jsp?EID=23087
Follow these steps for using WML instead of HTML from within JSP.
1) Make sure that the following is added to your MIME types file of your web server
and restart it: File Extension = .wml MIME Type = text/vnd.wap.wml
2) (From this point forward, you would do the following inside your servlets just as
you would inside your JSP files.) In your JSP file set your response type to text/wml
(normally it's text/html or text/plain for HTML).
3) Instead of outputting HTML code inside your JSP file, you just output WML code.
You can do this different ways: you can just use the
out.println("<wml>");
...
out.println("<card>");
...
or you could create WML classes in Java and just have a class for each WML tag
(WML is a small set of HTML, so you will have around 30 classes). Each WML class
would appropriately handle the syntax specific to itself and handle you placing data
into this syntax. Each class would also have a toString() method. From here, in your
JSP file, wherever you want your WML code, just write Java (you have the WML
classes), then to output the WML code, you would write out.println(wml.toString());
The wml.toString() method would call all of the other classes' (Card, Select, etc.)
toString() method to output all of the WML syntax. This design works well because if
the WML syntax changes and you have 100 JSP files with WML syntax inside, you
would have to change every one on them; using the WML classes, if the WML syntax
changes, you just have to change that particular class associated to whatever tag
changed, and then recompile your class.
Now, keep in mind that there is one problem with outputting WML through JSP - if
your web phone is trying to call a JSP file (not through a servlet), and there is a
problem in which the JSP file outputs an error, whatever is handling your JSP files will
probably output an error in HTML format, not WML, and therefore your phone
browser will not be able to interpret this and will give you an error page built into the
phone browser. For example, if you are using JRun to run your JSP files and it is not
up and running, you will receive an error in HTML. You could develop an error
handling system for capturing JSP errors and if you are expecting WML, you could
return an error page in WML.
</card> </wml>
Is there an easier way to create a DTD file? Are there tools that can help me
do so?
Location: http://www.jguru.com/faq/view.jsp?EID=38211
Created: Apr 20, 2000 Modified: 2000-04-29 08:37:18.777
Author: Egil Ølberg (http://www.jguru.com/guru/viewbio.jsp?EID=38147) Question
originally posed by Anil Punjabi
(http://www.jguru.com/guru/viewbio.jsp?EID=23218
(From Egil Ølberg) Yes, the tool I use can be downloaded at:
• IBM AlphaWorks
(From Benoit Xhenseval) Yes there are. It is also recommended to use some tools as
the DTDs will evolve into XML Schema soon and those tools have early suuport for
schemas.
Can I get an example that works on documents which are not DTD-specific
but generic?
Location: http://www.jguru.com/faq/view.jsp?EID=38686
Created: Apr 21, 2000 Modified: 2000-04-24 20:00:47.231
Author: Bruce Martin (http://www.jguru.com/guru/viewbio.jsp?EID=12) Question
originally posed by shravan mishra
(http://www.jguru.com/guru/viewbio.jsp?EID=38208
The xBeans project includes many examples of Java code that works on documents
of any DTD. Such code requires you to essentially interpret the DOM representation
of the document and not depend on any particular elements, attributes or document
structure.
Why would XML be a better solution than a typical delimited text file for B2B
(business to business applications), or representing data in general? I can
take a flatfile, I can parse it and extract data, and then present that data in
different ways using java such as HTML or WML. So, why would I want to
complicate things with DTDs, parsers, and APIs needed to extract and
display data?
Location: http://www.jguru.com/faq/view.jsp?EID=39592
Created: Apr 24, 2000 Modified: 2000-04-28 14:30:37.382
Author: Nicola Ken Barozzi (http://www.jguru.com/guru/viewbio.jsp?EID=39153)
Question originally posed by Matt Woody
(http://www.jguru.com/guru/viewbio.jsp?EID=36408
There are many possible answers; XML can be used, as ASCII text files, in many
ways. In fact it is also called the ASCII of the future (even if ASCII an XML define
two different things).
In B2B the main reason is that it separates the data contained in a document and its
structure from the presentation. This means that if you want to change the
presentation you can simply change the XSL (stylesheet) and keep the data
unchanged. Not to mention how it is easy to change a stylesheet compared to parse
it and extract data, and then present that data in different ways using java such as
HTML or WML.
But the main advantage is that it is easy to convert XML to XML having a different
DTD or schema. For example, firm A has to send a purchase order to firm B. It sends
it in XML. Suppose also that firm B keeps track of purchase orders written in XML.
Even if the two firms use different XML DTDs or schemas it is easy to use XSL to
change from a format to another. Now firm B can insert the order in its database.
Now imagine doing this with a a typical delimited text file ...
On the site W3 Consortium site there is XML in 10 points.
Response: The idea is that there are standard industry wide DTDs for exchanging
data. Using XSLT technology, two enterprises can exchange data according to the
standard DTD. XSLT allows each enterprise to translate its XML data to and from the
standard.
What is the most efficient way to create XML documents from Java objects
and vice versa?
Location: http://www.jguru.com/faq/view.jsp?EID=40590
Created: Apr 26, 2000 Modified: 2000-05-01 08:51:25.623
Author: Nicola Ken Barozzi (http://www.jguru.com/guru/viewbio.jsp?EID=39153)
Question originally posed by Bernhard Brandmair
(http://www.jguru.com/guru/viewbio.jsp?EID=36062
• Parsing a big XML file: you should use the SAX API, which is event driven;
this means that the document is not duplicated in memory and the parsing is
fast, but is limiting beacuse you cannot go back and forth on the tree or add
or subtract branches (input only);
• Parsing a small XML file: the DOM API is much easier to use (remember to
include the DTD so that unmeaningfull white spaces do not interfere with
parsing), and the memory usage is small; you gain also in flexibility, because
you can go back and forth on the tree, add or subtract branches and output
the tree (not part of the DOM standard API but usually present in
implementations);
• Writing XML files with basically the same structure: just output the tags
as String like
out.println("<MYTAG>"+InTagString+"</MYTAG>");
• Writing XML files with variable structure: use the DOM API , which
represent the XML as a tree; it is easy to bind a DOM tree to a JTree
component, the code that does it is in the Jva XML Tutorial on the Javasoft
site.
Now Sun is writing a binding specifications to tie the XML to Java classes (JSR-
000031 XML Data Binding Specification), but at the time of the writing it isn't ready.
Detailed info on the use of it is at White Papers about XML Technology .
Comments and alternative answers
Some alternatives
Author: Stefan Stefansson (http://www.jguru.com/guru/viewbio.jsp?EID=1119203),
Aug 10, 2005
There are a few alternatives nowadays:
For the purpose of the original question, serializing Java Objects to and from XML
files, one of the coolest things I've seen is XStream:
• http://xstream.codehaus.org/
Regards, Stefan.
How do you print the contents of an XML document using the DOM, i.e.
using the org.w3c.dom.* interfaces?
Location: http://www.jguru.com/faq/view.jsp?EID=42105
Created: Apr 28, 2000 Modified: 2000-04-29 08:05:08.976
Author: Pramod Hirole (http://www.jguru.com/guru/viewbio.jsp?EID=41443)
Question originally posed by Gene De Lisa
(http://www.jguru.com/guru/viewbio.jsp?EID=38746
The org.w3c.dom.* package provides a Node interface which defines methods such
as "getNodeName()" ,"getNodeType()", "getNodeValue()" for getting the information
about the current node. There are also other methods such as "getPreviousSibling()",
"getNextSibling()", "getChild()" for traversing the XML document.
Given a reference to Document you can traverse through the document using the
above methods, printing each node as it is visited.
XML namespaces are simple way to give unique names to elements and attributes
used in XML document. Namespaces enables the programmers to select the XML
tags for processing depending upon the application requirment.
<?xml version="1.0"?>
<book xmlns='www.amazon.com:books'
xmlns:isbn='urn:ISBN:0-395-36341-6'>
<title>Cheaper by the Dozen</title>
<isbn:number isbn:type='Hard_Copy'>123456789<isbn:number>
<notes>
use of namespaces
Author: prasenjit narwade (http://www.jguru.com/guru/viewbio.jsp?EID=498645),
Sep 21, 2001
...and when are they used ?
I am attempting to use the XML parser provided by sun jaxp1.0. When I try
to get an instance of DocumentBuilderFactory using the static method
newInstance(), it throws a FactoryConfigurationError exception at runtime.
How can i do to overcome this?
Location: http://www.jguru.com/faq/view.jsp?EID=44859
Created: May 4, 2000 Modified: 2000-05-09 15:43:34.101
Author: M.Kumar Sankar (http://www.jguru.com/guru/viewbio.jsp?EID=31021)
Question originally posed by M Kumar Sankar
(http://www.jguru.com/guru/viewbio.jsp?EID=43788
You have to include the following class in the import section and set the classpath to
that directory. import com.sun.xml.parser.DocumentBuilderFactoryImpl;
Comments and alternative answers
jaxp.jar
crimson.jar
xalan.jar
How can I map data from a DB2 UDB for AS/400 into an XML document and
the associated DTD ?
Location: http://www.jguru.com/faq/view.jsp?EID=45449
Created: May 6, 2000 Modified: 2000-05-09 15:55:15.531
Author: Carlos Ortiz (http://www.jguru.com/guru/viewbio.jsp?EID=45447) Question
originally posed by leonardo polon
(http://www.jguru.com/guru/viewbio.jsp?EID=38637
Since V4R2 of the OS400 IBM has released two Java packages the JT400.jar and
DB2_CLASSES.zip. With these you have access to almost all the funcionality of the
AS400 system (program calls, dataqueues, spool files, etc..). It also implements a 4
level JDBC Driver and record level access to physical files.
With these tools I think you have all the information to map as400 datasources to
XML files.
Has anyone parsed an XML dtd to create a DOM object? I don't know if that
is possible or not, if it isn't how could I get an object containing all the
attributes allowed for a given element?
Location: http://www.jguru.com/faq/view.jsp?EID=46977
Created: May 10, 2000 Modified: 2000-05-15 20:43:47.941
Author: Christoph Krüger (http://www.jguru.com/guru/viewbio.jsp?EID=30208)
Question originally posed by Gregory Van Ass
(http://www.jguru.com/guru/viewbio.jsp?EID=34607
You might want to have a look at the Oracle XML class generator. This neat little Java
API allows you to load a DTD and have each element generated as .java class files.
In a second step you can use these class files to build an application which generates
DOM-objects according to the DTD. It's all pretty well documented in the included
samples, so I'm leaving that to you.
Comments and alternative answers
Certainly you can. But for that you need to use XSL technology. Include an XSL
stylesheet at the begining of your XML with a processing instruction. In the XSL file
you can provide form and text boxes and so on. The XSL file may look as follows.
<?xml version="1.0" ?>
<xml:stylesheet mlns:xsl="http://www.w3.org/TR/WD-xsl>
<xsl:template match="/" >
<xsl:apply-templates select="/records/name" />
<xsl:template>
<xsl:template match="name[end()]" >
<html>
<body>
<form action="http://xxxx/servlet/yy">
<input type=text name="tt">
<xsl:attribute name="value"><xsl:value-of />
<xsl:attribute>
</form>
</body>
</html>
<xsl:template>
<xsl:stylesheet>
The main thing to observe here is the attribute values you want to provide
dynamically should be generated by using
<xsl:attribute name="xxx"> xxx value <xsl:attribute>
template. The given sample will create a form with one text field, and assigns the
value of the last name element in your XML file.
Comments and alternative answers
What is WML?
Location: http://www.jguru.com/faq/view.jsp?EID=50957
Created: May 17, 2000 Modified: 2000-09-12 19:35:10.307
Author: Niki Scevak (http://www.jguru.com/guru/viewbio.jsp?EID=49639) Question
originally posed by John Zukowski PREMIUM
(http://www.jguru.com/guru/viewbio.jsp?EID=7
WML is a markup language based on XML and is intended for use in specifying
content and user interface for narrowband devices, including cellular phones and
pagers.
Comments and alternative answers
WML was developed from the earlier proprietary markup language HDML (Handheld
Device Markup Language).
The first part of this question was answered by M.Kumar Sankar here.
How you handle your POSTs and GETs will depend entirely on how your system
works. You can define the form action to be whatever you want it to be. If you want
to store the data submitted somehow however it might be handy to convert the
submitted data back to XML. Something like:
<fieldname>value</fieldname>
should do the trick for most simple forms. This should keep your "display" code clean
since you won't have to display anything other than XML.
If the amount of stored data gets bigger you might want to look at using an XML
store of some sort. Products like eXcelon, Tamino etc. might be what you need.
Originally known as "RDF Site Summary", RSS, the Rich Site Summary format is the
de facto standard meta-data format for news headlines over the web.
WebReference's RSS page contains a number of helpful links to information on RSS.
What is the best way to convert HTML to XML, separating the content(data)
from presentation in HTML? Are there any Java API's that we can make use
of?
Location: http://www.jguru.com/faq/view.jsp?EID=66681
Created: Jun 6, 2000 Modified: 2000-10-11 09:33:33.868
Author: Brill Pappin (http://www.jguru.com/guru/viewbio.jsp?EID=60239) Question
originally posed by Praveen Paranjay
(http://www.jguru.com/guru/viewbio.jsp?EID=40359
Try Cocoon and ECS, or JetSpeed from the Apache group (java.apache.org).
There aren't really any APIs specifically for doing this. What do you want to do with
the HTML-data after it has been converted to XML? If all you want to do is display it
again using different style-sheets you should consider converting the HTML to
XHTML. XHTML is simply an XML compliant form of HTML
If you want to convert the HTML to XML compliant with a DTD or schema of your own
making then doing it can pose many problems. It all depends on the HTML. Do all
the HTML-files use the same "template"? Then it is possible to write a program to
convert it. If they are all different it is probably easy to do it by hand.
Comments and alternative answers
1. Data from database to XML: Depends on the complexity of your data. A simple
table is easily convert like:
<fieldname1>data</fieldname1>
<fieldname2>data</fieldname2>
etc.
When you have linked tables use the primary keys to creates a more hierarchical
representation:
<field1fromtable1>data</field1fromtable1>
<field2fromtable1> (suppose this is primary key)
<field1fromtable2>data</field1fromtable2>
etc. etc.
</field2fromtable1>
etc.
For more a more indepth discussion take a look at The XML Handbook or a similar
publication.
Some databases can generate XML directly (Oracle 8i being one of them). The
method described above can be used when your database doesn't do this.
Storing it on disk will of course increase performance but lose flexibility. In other
words, if you store in on disk you'll have to check every time whether or not the data
you need has changed in the database. If so you'll have to generate the XML file
again. If your conversion code is fast enough you don't have to save it into a file
everytime. You might consider doing it anyway as a form of result caching though.
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="somestylesheet.xsl" ?>
The second line make the reference to the stylesheet you want to use. When given
an XML containing this line IE5 for instance will simply get the XSL in question and
use it to transform the XML for you. You can change this line everytime you output
the XML. If you are serving up XML from disk you might want to leave out the header
and add it at the time you are serving it to the client. A simple servlet should do the
trick.
Bradley.
To Dynamically generate xml and save it into hard disk and then create its xsl and then generate th
Author: pravin sharma (http://www.jguru.com/guru/viewbio.jsp?EID=1161628), Apr 28, 2004
GenerateXml.java//This file will connect to to ur database fetch records and store it in the disk as an xml
import java.io.*; import java.sql.Driver; import java.util.*; public class GenerateXml { public void getDa
new Properties(); prop.put("user","sa"); prop.put("password","sa"); Connection con = null; Statement stm
null; List user = new ArrayList(); List dept = new ArrayList(); List mail = new ArrayList(); try { Driver d
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); con =
driver.connect("jdbc:microsoft:sqlserver://SRV03\\PREDATOR_O:1433;user=sa;password=sa;DatabaseN
stmt = con.createStatement(); rs = stmt.executeQuery("select * from Employee"); while (rs.next()){ Strin
(rs.getString("username")); String department = (rs.getString("department")); String email = (rs.getString
user.add(username); dept.add(department); mail.add(email); } ByteArrayOutputStream baos = new ByteA
PrintStream ps = new PrintStream(baos); ps.println("<?xml version=\"1.0\"?>\r\n"); ps.println("<Templat
user.size(); Iterator itr1 = user.iterator(); Iterator itr2 = dept.iterator(); Iterator itr3 = mail.iterator(); while(
ps.println("<UserName>"); ps.print(itr1.next()); ps.println("</UserName>"); ps.println("");ps.println("<p
ps.println(itr2.next()); ps.print("");ps.println("</product>"); ps.print("");ps.println("<email>"); ps.println(
ps.println("</email>"); } ps.println("</Template>"); FileOutputStream fos = new FileOutputStream("Emp
baos.writeTo(fos); fos.close(); }catch (Exception e){ e.printStackTrace();} } public static void main(Strin
xml = new GenerateXml(); xml.getData(); } } then generate the xsl code Employee.xsl <?xml version="1
8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:template match="/"> <fo:root
xmlns:fo="http://www.w3.org/1999/XSL/Format"> <fo:layout-master-set> <fo:simple-page-master maste
margin-right="1.0cm" margin-left="1.0cm" margin-bottom="2cm" margin-top="1cm" page-width="21cm
> <fo:region-body margin-top="1cm" margin-bottom="1.0cm"/> <fo:region-before extent="1cm"/> <fo:r
extent="1.5cm"/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference
flow-name="xsl-region-body"> <xsl:apply-templates select="Template"/> </fo:flow> </fo:page-sequence
</xsl:template> <xsl:template match="Template"> <fo:block font-size="10pt" font-family="verdana" col
align="center"> <xsl:apply-templates select="UserName"/> <xsl:apply-templates select="product"/> <xs
select="email"/> </fo:block> </xsl:template> <xsl:template match="UserName"> <fo:block> <xsl:apply-
select="UserName"/> </fo:block> </xsl:template> <xsl:template match="UserName"> <fo:block> <xsl:v
</fo:block> </xsl:template> <xsl:template match="product"> <fo:block> <xsl:apply-templates select="pr
</xsl:template> <xsl:template match="product"> <fo:block> <xsl:value-of select="."/> </fo:block> </xsl
match="email"> <fo:block> <xsl:apply-templates select="email"/> </fo:block> </xsl:template> <xsl:tem
<fo:block> <xsl:value-of select="."/> </fo:block> </xsl:template> </xsl:stylesheet> and then write the co
using fop. XmlToPdf.java package intentia; import java.io.ByteArrayOutputStream; import java.io.File; i
java.io.FileOutputStream; //import org.apache.avalon.framework.logger.ConsoleLogger; //import
org.apache.avalon.framework.logger.Logger; import org.apache.fop.apps.Driver; import org.apache.fop.a
org.apache.fop.apps.XSLTInputHandler; public class XmlToPdf { public void PDF () { try { Driver drive
driver.setRenderer(Driver.RENDER_PDF); //Logger log = new ConsoleLogger(ConsoleLogger.LEVEL_
//driver.setLogger(log); File xml = new File("Employee.xml"); File xsl = new File("Employee.xsl"); Inpu
new XSLTInputHandler(xml,xsl); FileOutputStream filePDF = new FileOutputStream("Employee.pdf");
driver.setOutputStream(filePDF); driver.render(inputHandler.getParser(),inputHandler.getInputSource());
out = new ByteArrayOutputStream(); byte[] content = out.toByteArray(); filePDF.write(content); driver.r
filePDF.close(); } catch (Exception e) { System.out.println(" error is " + e); } } public static void main(St
test = new XmlToPdf(); test.PDF(); } } This will generate your pdf
I am generating an XML file dynamically from a Java program and I want
the same to display to the browser with the help of XSL file. I want to select
the XSL file dynamically. How can I do that?
Location: http://www.jguru.com/faq/view.jsp?EID=64656
Created: Jun 6, 2000 Modified: 2000-06-06 17:08:26.448
Author: Thijs Stalenhoef (http://www.jguru.com/guru/viewbio.jsp?EID=31863)
Question originally posed by M.Kumar Sankar
(http://www.jguru.com/guru/viewbio.jsp?EID=31021
In order for the browser (IE 5 is the only shipping browser at this time to support
XML and XSL) to know which XSL you want it to use you have to have to header that
looks something like this:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="yourstylesheet.xsl" ?>
in your XML. The second line defines which stylesheet will be used. Since you are
generating your XML dynamically, changing this second line to point to another XSL
file should be easy.
http://java.sun.com/products/jfc/tsc/articles/persistence/index.html
After generating an XML file dynamically from a Java program I want the
generated file to be displayed on the client's browser. How can I do that?
Location: http://www.jguru.com/faq/view.jsp?EID=46915
Created: Jun 9, 2000 Modified: 2000-06-09 16:27:25.756
Author: M.Kumar Sankar (http://www.jguru.com/guru/viewbio.jsp?EID=31021)
Question originally posed by M.Kumar Sankar
(http://www.jguru.com/guru/viewbio.jsp?EID=31021
IBM's XML parser for Java provides a TXDocument class in which there is a method
printWithFormat(writer). Give the servletResponseWriter to this argument so that the
document will be displayed on to the client's browser, provided the browser supports
the XML file format. When generating the XML file dynamically be careful to ensure
that there are no null values, otherwise an exception will be thrown by
printWithFormat.
Comments and alternative answers
I have code in which I'm using XLinks. I'm not getting any error but the
XLink is not working. I am using IE5. What is the reason for this?
Location: http://www.jguru.com/faq/view.jsp?EID=64657
Created: Jun 9, 2000 Modified: 2000-06-09 16:37:59.852
Author: Thijs Stalenhoef (http://www.jguru.com/guru/viewbio.jsp?EID=31863)
Question originally posed by Siva Prasad Balaraju
(http://www.jguru.com/guru/viewbio.jsp?EID=46435
IE 5 does not support XLink or XPointers at the moment. A reason for this might be
that XLink is still a "working draft" at W3.org.
A way to work around this for the time being might be to use an XSL to transfer
them to normal HREF's.
If you are familiar with the PostScript language you could simply write an XSL to do
the work for you. The actual work can then be done using some form of XSL-
Transformation tool (Xalan is one, http://xml.apache.org").
There are some commercial packages that do it for you (sorta) but they are
generally very expensive.
FOP is the world's first print formatter driven by XSL formatting objects. It is a Java
application that reads a formatting object tree and then turns it into a PDF document.
The formatting object tree, can be in the form of an XML document (output by an
XSLT engine like XT or Xalan) or can be passed in memory as a DOM Document or
(in the case of XT) SAX events.
The retepPDF library allows any Java application that is capable of printing, to
generate PDF (portable Document Format) files. These files can then be published on
the Internet, sent by mail, and then viewed either in a web browser (using the Adobe
Acrobat PlugIn) or by using a suitable PDF viewer.
Licencing:
The PDF library is distributed under the GNU General Library Public Licence as a
precompiled jar file, and as source in tar.gz format.
As a caveat: I have not tried out any of these in a serious project, so I cannot give any
kind of information regarding usability or performance etc.
Location: http://www.jguru.com/faq/view.jsp?EID=91201
Created: Jul 5, 2000 Modified: 2000-07-05 12:32:38.189
Author: Davanum Srinivas (http://www.jguru.com/guru/viewbio.jsp?EID=2011)
Question originally posed by Nicola Ken Barozzi
(http://www.jguru.com/guru/viewbio.jsp?EID=39153
Yes, it is possible. Use the following XSL file.
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="html" indent="yes"/>
<xsl:variable name="my-user-list" select="//user" />
<xsl:variable name="my-user-list2"
select="//user[not(./@firstname=following::user/@firstname)]" />
<xsl:template match="/">
<users>
<xsl:for-each select="$my-user-list2">
<xsl:variable name="my-user" select="." />
<user>
<username>
<first>
<xsl:value-of select="$my-user/@firstname" />
</first>
<last>
<xsl:value-of select="$my-user/@lastname" />
</last>
<articles>
<xsl:for-each select="$my-user-list">
<xsl:variable name="my-user2" select="." />
<xsl:if test='//*[$my-user/@firstname = $my-
user2/@firstname]'>
<article>
<xsl:value-of select="$my-user2/@article" />
</article>
</xsl:if>
</xsl:for-each>
</articles>
</username>
</user>
</xsl:for-each>
</users>
</xsl:template>
</xsl:stylesheet>
The output is as follows:
<users>
<user>
<username>
<first>Jack</first>
<last>Jill</last>
<articles>
<article>Three</article>
</articles>
</username>
</user>
<user>
<username>
<first>John</first>
<last>Joe</last>
<articles>
<article>One</article>
<article>Two</article>
</articles>
</username>
</user>
</users>
The DevelopMentor SOAP FAQ is probably the best place to start. Microsoft also has a
SOAP FAQ.
We are getting the inputs using HTML forms (mostly text box). The
validations (like not empty) are done using Java Script. After the successful
validation we have to generate XML document by using Java script and the
same will be passed to EJB via JSP. Are there any solutions for generating
XML using Java Script?
Location: http://www.jguru.com/faq/view.jsp?EID=94679
Created: Jul 5, 2000 Modified: 2000-07-05 13:06:53.57
Author: Simon Brown (http://www.jguru.com/guru/viewbio.jsp?EID=44588)
Question originally posed by vetrivel chidambaram
(http://www.jguru.com/guru/viewbio.jsp?EID=87192
Whilst there don't seem to be any solutions for building XML using JavaScript, there
is another, maybe easier way that you can achieve the same result.
After validating the text fields on the client-side, you could POST the contents of the
form back to another JSP. This JSP could use one of the various XML libraries
available (e.g. Xerces from Apache or JAXP from Sun) to build the XML document for
subsequently passing it to your EJB.
Comments and alternative answers
Converting XML and XSL to HTML is exactly what IE5 does internally. This process is
called a transformation. XML is transformed, using an XSL stylesheet, to HTML. There
are many ways to do XSLT (XSL Transformation) and a lot of people/companies have
written Java classes to do this. Some are free other aren't.
I recommend you check out xml.apache.org for Xalan. This is a free and open-source
XSLT (and XPath!) engine and should be all you need.
How can an XML document like this be created with the JAXP API?
<address>
<name City="New York">
<first>John</first>
<last>Joe</last>
</name>
</address>
<address>
<name City="Boston">
<first>Jack</first>
<last>Jill</last>
</name>
</address>
Location: http://www.jguru.com/faq/view.jsp?EID=80888
Created: Jul 5, 2000 Modified: 2000-07-05 15:47:51.968
Author: M.Kumar Sankar (http://www.jguru.com/guru/viewbio.jsp?EID=31021)
Question originally posed by Jens Hilbert
(http://www.jguru.com/guru/viewbio.jsp?EID=59910
To generate an XML document using Jaxp the following sample code can help you.
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Document;
import org.w3c.dom.*;
import org.w3c.dom.Text;
import com.sun.xml.parser.DocumentBuilderFactoryImpl;
import com.sun.xml.parser.*;
import com.sun.xml.tree.*;
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
Element root = doc.createElement("root");
Element address = doc.createElement("address");
Element name = doc.createElement("name");
name.setAttribute("City","New York");
Element first = doc.createElement("first");
first.appendChild(doc.createTextNode("John"));
Element last = doc.createElement("last");
last.appendChild(doc.createTextNode("Joe"));
name.appendChild(first);
name.appendChild(last);
address.appendChild(name);
root.appendChild(address);
doc.appendChild(root);
XmlDocument tdoc = (XmlDocument)doc;
tdoc.write(new PrintWriter(System.out));
System.out.println("Document created successfully ...");
} catch(Exception e)
{
e.printStackTrace();
}
}
}
Note that it is one way. You can use XmlDocument object directly to get an
Docuemnt instance and use the above same methods to generate document. You can
place it in a loop so that any number of address nodes can be created.
Where can I get basic information about XML? Are there any good tutorials?
Location: http://www.jguru.com/faq/view.jsp?EID=91089
Created: Jul 5, 2000 Modified: 2000-07-05 16:38:33.084
Author: Davanum Srinivas (http://www.jguru.com/guru/viewbio.jsp?EID=2011)
Question originally posed by chetan chandawalla
(http://www.jguru.com/guru/viewbio.jsp?EID=69365
From Curtis Hatter: There are of good places to get information on xml.
1. www.xml.com
2. www.xml.org
3. www.webmonkey.com
4. www.w3.org
If you are a java developer you may wanna also check out these links.
1. www.alphaworks.ibm.com/formula/XML
2. www.java.sun.com/xml
There are plenty of others but those are good starting points. And the IBM and SUN
sites provide tutorials and information on how to use their Java XML parsers.
I describe a few easy steps to begin accessing XML data in Java in Lowering the
bar of the DOM API article at IBM's developerWorks.
The best book for XML is web. As this is still evolving technology, there are very few
books that cover entire XML. Even some of them may be very specific to onces
implementations. Some of the best sites to go through are:
1. W3C
2. xml.com
3. xml101.com
4. xmlinfo.com
In addition to these Sun, Oracle and IBM sites are also providing information in their
sites. The tutorials are mentioned in those sites.
How do I write and deploy a simple hello world program that uses XML and
can be seen in a browser. What is the required software to start working
with XML?
Location: http://www.jguru.com/faq/view.jsp?EID=58437
Created: Jul 6, 2000 Modified: 2000-07-06 11:45:08.93
Author: swarna kumar Reddy (http://www.jguru.com/guru/viewbio.jsp?EID=44506)
Question originally posed by deepak ghosh
(http://www.jguru.com/guru/viewbio.jsp?EID=54313
Remember though that XML is "nothing more" then a way to describe data in
structured way. A "hello world"-like program using XML doesn't really exist, as XML
isn't a programming language.
If you want to use Java to output XML that can be viewed in a browser you should
use Java Server Pages or a Java Servlet that outputs XML. You do this in a way
analoguous to outputting HTML using JSP or Servlets.
<?xml version="1.0"?>
<?xml:stylesheet type="text/xsl" href="Hello.xsl"?>
<Greet>
<wish>
<info>Hello World</info>
</wish>
</Greet>
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<head>
<title> Hello World Application </title>
</head>
<body>
<xsl:for-each select="Greet/wish">
<xsl:value-of select="info" />
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Now open the Hello.xml file in a browser that supports XML, such as IE 5.0.
I have two XML documents and want to combine them into one single
document. How do I go about doing this?
The rules are simple,
1. If an attribute is present in both files but have different values, then the
one in the 2nd file should be put into the combined document.
2. If the 2nd file has some tags/attributes that are not present in the 1st file
then it should be added to the combined document.
Please check out IBM's alpha works page. The XMLTreeDiff utility can be used to
perform your task.
Is any method in Java which can create the Doctype parameter in the XML
document, that is to produce !DOCTYPE Response SYSTEM
"MyResponse.dtd"> ?
Location: http://www.jguru.com/faq/view.jsp?EID=99425
Created: Jul 10, 2000 Modified: 2000-07-19 11:18:04.743
Author: Oliver Springauf (http://www.jguru.com/guru/viewbio.jsp?EID=32379)
Question originally posed by Sonu TheKool
(http://www.jguru.com/guru/viewbio.jsp?EID=3468
There is no such method in the DOM spec. However, the implementation you are
using might provide one. In Sun's JAXP implementation, there is the method
XmlDocument.setDoctype(String dtdPublicId, String dtdSystemId, String
internalSubset) that you can use. Unfortunately, there is no official documentation
on the implementation, and you are losing your independence from the
implementation when you are calling these methods.
Is there a way to generate XSL from HTML? That is, the generated style
sheet would represent the style of the HTML page.
Location: http://www.jguru.com/faq/view.jsp?EID=102196
Created: Jul 14, 2000 Modified: 2000-07-16 20:52:09.006
Author: Håkan Cervin (http://www.jguru.com/guru/viewbio.jsp?EID=43294)
Question originally posed by stephane giner
(http://www.jguru.com/guru/viewbio.jsp?EID=99360
No. The XML to HTML transformation is a many to many relation. One HTML page
can be generated by several different style sheets, depending on the data in the XML
file.
Can one transfer images & other BLOB objects using XML? How?
Location: http://www.jguru.com/faq/view.jsp?EID=103038
Created: Jul 15, 2000 Modified: 2000-07-19 11:12:26.523
Author: Software Framework (http://www.jguru.com/guru/viewbio.jsp?EID=61156)
Question originally posed by Anil Punjabi
(http://www.jguru.com/guru/viewbio.jsp?EID=23218
You may want to use mime to hold the XML and the binary data. Alternatively you
can use a CDATA block or you can encode the binary data using base64 encoding.
Finally, you can just store a URL to the XML document that points to the data.
I encountered this problem using SAX. The proposed answer is correct: the problem
is that SAX parsing expects the stream to contain a single well formed document ... so
<e1>data</e1>
<e2>datatoo</e2>
looks like two documents with root elements e1 & e2. So as suggested wrap the
whole transmission on the stream:
<XML-STREAM>
<e1>data</e1>
<e2>datatoo</e2>
</XML-STREAM>
We have successfully used this on XML streams that are open for hours to send
messages from one app to another.
I have the same problem, and after trying solutions I still remain with the same
problem! (Error: SAXException during parseXML():The root element is required
in a well-formed document.)
<XML-STREAM>
<e1>data</e1>
<e2>datatoo</e2>
</XML-STREAM>
How do I render an HTML page using XSL if I have a style sheet and the
data reside in a data object? I do not want to output the data to a text file
and parse it.
Location: http://www.jguru.com/faq/view.jsp?EID=103048
Created: Jul 15, 2000 Modified: 2000-07-19 12:02:24.339
Author: Software Framework (http://www.jguru.com/guru/viewbio.jsp?EID=61156)
Question originally posed by khien siow
(http://www.jguru.com/guru/viewbio.jsp?EID=55971
You don't have to output the objects to a file. You can output to a String and then
parse the string.
If you don't want to convert your objects to an xml document (in a file or string)
then you to have generate the DOM objects or SAX events so that then can be fed to
a XSLT processor. Xalan from xml.apache.org can take input from DOM and SAX
event generators.
Set the content type to text/xml. An XML file is just a text file. You only have to
change the content type so that server or client knows what it is being sent.
Can I validate a DOM using a DTD and return the errors to a logfile?
Location: http://www.jguru.com/faq/view.jsp?EID=103050
Created: Jul 15, 2000 Modified: 2000-07-19 12:00:10.352
Author: Software Framework (http://www.jguru.com/guru/viewbio.jsp?EID=61156)
Question originally posed by Venkata R Kotte
(http://www.jguru.com/guru/viewbio.jsp?EID=20756
You have to read the documentation of your DOM parser. Typically validation is done
on XML strings before the DOM is generated. Check out the docs for xerces at
www.apache.org.
Comments and alternative answers
The IBM parser extends the DOM to support querying of the DTD.
How can I use in XSL "value-of" to get the content of a tag, which includes
other tags. I tried that and I got only the content of all tags but I also want
to have the other tags.
Location: http://www.jguru.com/faq/view.jsp?EID=103053
Created: Jul 15, 2000 Modified: 2000-07-17 08:13:23.251
Author: Software Framework (http://www.jguru.com/guru/viewbio.jsp?EID=61156)
Question originally posed by Nermin Denizer
(http://www.jguru.com/guru/viewbio.jsp?EID=94409
You should use xsl:copy or xsl:copy-of.
See http://metalab.unc.edu/xml/books/bible/updates/14.html
Search for xsl:copy
<document attrib="foo">>
<body>
<item>1</item>
<item>2</item>
<item>2</item>
<body>
</document>
If I do
<xml:for-each select="body/item">
how can I access
document/@attribute
since
<xml:value-of select="document/@attribute"/>
would now be equivalent to body/item/document/@attribute?
Location: http://www.jguru.com/faq/view.jsp?EID=103902
Created: Jul 17, 2000 Modified: 2000-07-19 12:07:48.263
Author: Peter Ciuffetti (http://www.jguru.com/guru/viewbio.jsp?EID=103867)
Question originally posed by Dan Bradley
(http://www.jguru.com/guru/viewbio.jsp?EID=50679
All you need to do is start the pattern with slash. E.g.
<result>
<xsl:for-each select="body/item">
<item>
<xsl:attribute name="attrib">
<xsl:value-of select="/document/@attrib"/>
</xsl:attribute>
<xsl:value-of select="."/>
</item>
</xsl:for-each>
</result>
Will produce
<result>
<item attrib="foo">1</item>
<item attrib="foo">2</item>
<item attrib="foo">3</item>
</result>
Comments and alternative answers
level-up
Author: Damic Orion (http://www.jguru.com/guru/viewbio.jsp?EID=747316), Feb 5,
2002
<xsl:value-of select="../@attrib"/> works too! If you wanna go up more than one
level, repeat '../' as much as the number of levels you want to go up...
How does one use XSLT to output the name of an element or an attribute?
For example, given input:
<a b="c"/>
where a, b can be anything, how would you use XSLT to produce:
<b a="c"/>
Basically, I'm looking for XSLT fragment like the following:
<xsl:template match="*">
<xsl:element name="nameof(attribute[1])">
<xsl:attribute name="nameof(.)">
<xsl:value-of select="@attribute[1]"/>
</xsl:attribute>
</xsl:element>
</xsl:template>
Location: http://www.jguru.com/faq/view.jsp?EID=103920
Created: Jul 17, 2000 Modified: 2000-07-19 11:16:11.532
Author: Peter Ciuffetti (http://www.jguru.com/guru/viewbio.jsp?EID=103867)
Question originally posed by Software Framework
(http://www.jguru.com/guru/viewbio.jsp?EID=61156
What you need is something like this:
<xsl:template match="root">
<result>
<xsl:for-each select="*">
<xsl:element name="{local-name(@*)}">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="@*"/>
</xsl:attribute>
</xsl:element>
</xsl:for-each>
</result>
</xsl:template>
This uses the local-name() function of XPATH to obtain the name of the element and
the name of the first attribute in that element. It will transform:
<root>
<a b="c"/>
<d e="f"/>
<g h="i"/>
</root>
Into...
<result>
<e d="f"></e>
<h g="i"></h>
</result>
Note: When you pass local-name a node set (like @*), it returns only the name of
the first node in document order. So you can't use this trick to obtain the name of a
second or subsequent attribute.
There are a number of ways to do this, but it depends on what you need. <bl>
Some database support storing and retrieving data natively. Now Oracle and DB2
support XML as native format and also as query language (XQL). Support for other
database is on way. For storing specific XML datas is best way parse XML document
with some DOM parser (e.g. IBM, SUN, Oracle, ...) to memory and store it to
database how you like and back. Because if you are storing data you must deal with
some problems e.g. flat storing, recursion, structure parsing, datatype recognision,
formating which are not handled always right way in standard products.
You could use a standard relational database, but then it will be quite tricky to
maintain the hierarchical nature of XML documents.
You can use an Object Oriented database such as Ozone (which is written in
Java) to store the XML. This will preserve the hierarchy.
There are specialized databases for XML storage available. One of them is
www.dbxml.org (not yet released) but there are many others. www.xml.com has
several listed.
Loads of companies have jumped on the XML bandwagon, each with their own
unique ideas, features and quirks. My advice would be to look well at all that is being
offered, evaluate some and then pick what's best for the project you are working on.
</bl> Later Thijs adds:
This is a tricky question. You could of course use a simple SQL database and have a
table which takes just two entries, for instance:
You would then get it back by just doing a simple SQL query on "id" and returning
"xml-doc". This however does not give you much flexibility. You can't really have the
database return certain tags and/or parts of a given XML-document without first
grabbing the whole thing. What if I wanted to get every <PERSON> tag and its
contents out of each document? The amount of SQL queries would be absurd.
A second way of storing XML in a SQL-db is to try and preserve the hierarchical
structure of the XML by using multiple tables linked together by keys.
This works fine for preserving a single type of XML document. It becomes
cumbersome however once you start using loads of different types of documents, as
for every type of document you would need to create an (almost) entirely new set of
linked tables.
Of course you could go out and buy an XML store like eXcelon (which isn't really a
db) or Tamino (which is quite expensive) but there is another way:
Store your XML in an LDAP database. LDAP uses an hierarchical model for storing
information, which maps nicely to and from XML. It may seems weird at first, but it
works and the implementation of such a scheme is pretty straightforward. Once done
you can easily implement something like an XPath processor (which btw, maps nicely
to LDAP queries) to select various parts of your XML document.
jguru m writes:
Oracle iFS is will allow you to store xml documents in its file system and it will map
the xml data to tables so that you can do faster searching and indexing.
However, consider that this tool (and probably nearly every other tool) uses DOM to
parse the whole XML document. When importing large XML files, this can lead to
serious memory usage.
Therefor it's more efficient to use SAX parsing in a self-written tool (I couldn't find
an existing one) and writing the data using JDBC to the DB. The downside of SAX
are problems with hierarchical data and the mapping to many different tables. Use
SAX if your XML data is very flat and could be imported into one or two tables.
Another idea would be to transform the XML file using XSL to generate a SQL
import file, which you feed into the DB.
Where can I get information about XHMTL? What are some links to sites
which have been developed using xhtml?
Location: http://www.jguru.com/faq/view.jsp?EID=109030
Created: Jul 23, 2000 Modified: 2000-07-30 07:58:15.1
Author: Christoph Krüger (http://www.jguru.com/guru/viewbio.jsp?EID=30208)
Question originally posed by karthik krish
(http://www.jguru.com/guru/viewbio.jsp?EID=104317
Right now XHTML 1.0 is identical to HTML 4.01. This is done for compatibility
reasons. Beginning with the next release of XHTML there will be differences.
Information about those "standards" can be found on the W3C website.
Is there an XML parser (SAX/DOM) in C/C++ for VAX/VMS? Links for both
open source and commercial packages are welcome.
Location: http://www.jguru.com/faq/view.jsp?EID=109450
Created: Jul 24, 2000 Modified: 2000-07-30 07:55:33.39
Author: Dror Harari (http://www.jguru.com/guru/viewbio.jsp?EID=109440) Question
originally posed by Benoit Xhenseval
(http://www.jguru.com/guru/viewbio.jsp?EID=3363
See the expat XML 1.0 parser written in C. It ports easily to VAX/VMS although you
will need to use DECC rather than VAXC as the VAXC compiler does not support the
ANSI token pasting operator #.
expat can be found at this
site.
How can I use JUnit to ensure that my servlets/JSP are producing valid
HTML?
Location: http://www.jguru.com/faq/view.jsp?EID=110644
Created: Jul 25, 2000 Modified: 2000-07-26 15:34:48.697
Author: Tom Copeland (http://www.jguru.com/guru/viewbio.jsp?EID=1396)
There's the traditional, brute force way - write a JUnit test case that opens a
HttpURLConnection to your servlet, reads the content, and does various
String.indexOf() and String.subString() operations until you're satisfied that all is
well (or you're tired of hacking together String operations).
A slightly more elegant method is to use an XML parser. You can open the
connection, read the contents, feed it into your XML parser, get back a document,
and walk the DOM tree checking for elements which should be there. Better, but still
clunky.
A better way is to use HttpUnit. HttpUnit allows the test case to be written using the
same "words" as used in web pages - forms, tables, etc. You can write test cases like
this (this is from the example code):
public void testWelcomePage() throws Exception {
WebConversation conversation = new WebConversation();
WebRequest request = new GetMethodWebRequest(
"http://www.meterware.com/servlet/TopSecret" );
XPath
Author: Johannes Brodwall (http://www.jguru.com/guru/viewbio.jsp?EID=87292),
May 4, 2001
HttpUnit is indeed powerful. An easy way of checking the structure without mocking
too much around with text strings is to combine it with XPath.
import org.apache.xpath.XPathAPI;
import org.w3.dom.*;
This will test if the table in the response with the id attribute 'mytable' contains 10
rows.
Microsoft Internet Explorer 5.5 fully supports XPath. If you want to try it out, you
should download the July 2000 Microsoft XML SDK Beta See this Microsoft site. It has
all the documentation you need to get started. You can try it with C++, VB and
various scripting languages.
If you are the Java type, you might want to look up the Apache Xalan project which
includes, among other things, support for XPath.
Lastly, at the Oasis site, you can find almost anything you want to know about XPath,
XLink, XPointer and other related technologies - including links to software
implementations.
Please give me the source code to read XML data from String variable in Java and
also I need the code to insert the extracted XML data into Oracle database using
java
You might want to modify one of the XML4j samples to write to a file. This assumes
you're using plain server-side code, no bean or servlet issues addressed here.
The XML4J sample dom/DomWriter will write XML to standard output. It comes with
the source package (XML4J-src_3_0_1.zip). Here's what I did:
-- cut constructor---
public DOMWriter(String filename, String encoding, boolean canonical)
throws Exception {
out = new PrintWriter(new
OutputStreamWriter(new FileOutputStream(filename), encoding), true);
this.canonical = canonical;
}
---cut---
I have 10 different DTD's and one specific part of the DTD repeats in all of
the DTD's. I want to store this repeating DTD as another separate DTD and
use it as a reference in all the other DTD's.
For example, I have an Element with UserId and Password which is common
for all the DTD's.
How can I store the above as a DTD file and use its reference in other DTDs?
Location: http://www.jguru.com/faq/view.jsp?EID=126100
Created: Aug 14, 2000 Modified: 2000-08-17 10:24:42.734
Author: Davanum Srinivas (http://www.jguru.com/guru/viewbio.jsp?EID=2011)
Question originally posed by Sonu TheKool
(http://www.jguru.com/guru/viewbio.jsp?EID=3468
Yes, this is possible using External Parameter Entities. Here's the sample logon.dtd
<!ELEMENT USERID (#PCDATA)>
<!ELEMENT PASSWORD (#PCDATA)>
XML is just an open way to express your data, this means that XML can be
transported with just about any protocol. For an example on using XML over HTTP
can be found at http://developer.java.sun.com/developer/qow/archive/84/index.html
I am currently using the DOM, but I want to use an external DTD with my
XML file. With SAX you can parse the external DTD and associate it wih the
XML file. How do I do that with the DOM?
Location: http://www.jguru.com/faq/view.jsp?EID=126121
Created: Aug 14, 2000 Modified: 2000-08-21 09:52:22.524
Author: Davanum Srinivas (http://www.jguru.com/guru/viewbio.jsp?EID=2011)
Question originally posed by Nakaeda Benskin
(http://www.jguru.com/guru/viewbio.jsp?EID=46721
If you are using JAXP from Sun there are two things you can do.
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
Second, using the EntityResolver only seems to work with fully qualified URI's -
"http://www.domain.com/my.dtd". I can't seem to get it to work with a relative URI -
"my.dtd". Any idea's how to resolve a relative URI using DOM?
thanks, John
InputStream requestDtd =
context.getResourceAsStream("my.dtd");
return retVal;
Here is a snippet from the XML Bible written by Elliotte Rusty Harold.
"URI stands for Uniform Resource Identifier. URIs are similar to URLs but allow for
more precise specification of a linked resource. In theory, URIs separate the resource
from the location so a web browser can select the nearest or least congested of
several mirrors without requiring an explicit link to that mirror.
You can transform an XML document to a JTree because XML has a tree structure.
You can get information from Sun's XML tutorial
http://java.sun.com/xml/docs/tutorial/dom/4_tree.html
http://java.sun.com/xml/docs/tutorial/dom/3_tree.html
International text is used in the file by firstly specifying the encoding of the XML file
that you have specified. This is done setting the <?xml encoding='Shift_JIS'?> at
the beginning of the XML file (for example), which would specify the Microsoft Kanji
font to use for display. The names for these text styles are defined in the Unicode
standard and on the site http://www.isi.edu/in-notes/iana/assignments/character-
sets.
Using these character sets requires the user either to type in the equivalent ASCII
code from the keyboard or via the XML charcater specifier (#) For example:
Ampersand would be #38 (in Decimal) or #x26 (in Hex). If using extended character
sets such as the Japanese and Chinese characters two bytes would be used to
represent the letter/character required to be displayed.
Standard tags such as separators such as < and > and tags such as <?xml ?> would
be typed in as normally though content and tag names could be in the nominated
character set used.
I have to create a HTML page using XML and XSL that will have a button on
it that will open a url. How can I put the url address in an html link? The url
address is in xml tag.
Location: http://www.jguru.com/faq/view.jsp?EID=129654
Created: Aug 17, 2000 Modified: 2000-08-21 09:54:59.744
Author: Seok-jeong Hwang (http://www.jguru.com/guru/viewbio.jsp?EID=30431)
Question originally posed by vineet kumar
(http://www.jguru.com/guru/viewbio.jsp?EID=97463
Blabla
How can I check with the DOM-API, if a tag is empty (<mytag/>) or not
(<mytag>data</mytag>)?
Location: http://www.jguru.com/faq/view.jsp?EID=129842
Created: Aug 18, 2000 Modified: 2000-08-21 09:48:47.492
Author: Davanum Srinivas (http://www.jguru.com/guru/viewbio.jsp?EID=2011)
Question originally posed by Stephan Blasko
(http://www.jguru.com/guru/viewbio.jsp?EID=81535
There are many implementations of SAX and DOM that allow Java
Developers to manipulate XML documents. But are there any other
alternatives?
Location: http://www.jguru.com/faq/view.jsp?EID=132056
Created: Aug 22, 2000 Modified: 2000-08-28 12:40:25.033
Author: Davanum Srinivas (http://www.jguru.com/guru/viewbio.jsp?EID=2011)
You can use JDOM from http://www.jdom.org. The API is intuitive, Java-centric (e.g.
it uses Java Collections) and is optimized for Java.
Comments and alternative answers
The DOM is simpler to implement, but because it reads the entire XML document into
a tree structure in memory, it is not appropriate for extremely large documents or on
memory-constrained devices such as PDAs and cell phones.
SAX uses an event driven model to notify the application of document elements as
it's reading the document. This makes it more suitable if memory is a concern, or for
large documents, because any content your application doesn't care about can be
immediately discarded without consuming memory. Because it is event driven, it can
be more difficult to set up the appropriate callback routines, etc. than to use the
DOM.
A validating processor checks the structure of a document against the rules specified
in a DTD. A non-validating processor only checks to make sure that the document
conforms to the rules of XML.
Trying to build Tomcat, I get a message "No JAXP compliant XML parser
found". Where do I get this parser from and where do I put it?
Location: http://www.jguru.com/faq/view.jsp?EID=135925
Created: Aug 27, 2000 Modified: 2000-08-30 13:15:16.252
Author: Thomas Nagel (http://www.jguru.com/guru/viewbio.jsp?EID=68546)
Question originally posed by gaurav sharma
(http://www.jguru.com/guru/viewbio.jsp?EID=119338
[JAXP stands for "JavaTM API for XML Parsing" -A] you could get one from
http://www.javasoft.com/xml/download.html .
Unpack it somewhere on your system and make sure the parser.jar and the jaxp.jar
are included inside your CLASSPATH enviroment variable. [It should also go in
TOMCAT_HOME/lib/ I think that it's now included in Tomcat 3.2 distribution in that
directory. -Alex]
bye
Thomas
The DOM interfaces are actually specified in OMG IDL, so that the DOM can be
available in multiple programming languages. Implementations of the DOM in Java
can also implement the Serializable Java interface but they are not part of the DOM
standard.
Why would I want to use JSP when I could use XML/XSL and a parser
instead to achieve system independent results?
Location: http://www.jguru.com/faq/view.jsp?EID=137933
Created: Aug 29, 2000 Modified: 2000-08-30 06:52:50.87
Author: Software Framework (http://www.jguru.com/guru/viewbio.jsp?EID=61156)
Question originally posed by Dave Richardson
(http://www.jguru.com/guru/viewbio.jsp?EID=94918
I use JSPs to generate the content in a form that I think will be acceptable. I allow
xslt translations to handle the cases I didn't think of in advance. It allows the users
to make the final decission. The translations created by users are private and I don't
write or maintain them. (I do allow users to share their translations with each other).
How can I access XML data from a JSP file? I have many documents in XML.
I need the data to be included in HTML documents using JSP.
Location: http://www.jguru.com/faq/view.jsp?EID=138329
Created: Aug 30, 2000 Modified: 2000-09-01 09:03:33.41
Author: Peter Gelderbloem (http://www.jguru.com/guru/viewbio.jsp?EID=91670)
Question originally posed by Juan Zamakona
(http://www.jguru.com/guru/viewbio.jsp?EID=137327
You could use an XSL stylesheet that translates from your XML format to HTML. The
transformation can be done using something like xalan.
Alternatively, you could parse the XML files using the DOM or SAX APIs and extract
the relevant data.
Is there any way to pass parameters to XSL from outside the XSL, such as
from a JSP?
Location: http://www.jguru.com/faq/view.jsp?EID=138396
Created: Aug 30, 2000 Modified: 2000-09-01 08:58:09.069
Author: Peter Ciuffetti (http://www.jguru.com/guru/viewbio.jsp?EID=103867)
Question originally posed by Aisha Fenton
(http://www.jguru.com/guru/viewbio.jsp?EID=130238
The XSLT spec says that top-level xsl:param's and xsl:variable's can be set by the
processor at run-time, but its up to the processor to provide a mechanism for doing
so. These mechanisms are processor specific.
The Xalan XSLT processor, available at http://xml.apache.org, has a method for
setting top-level parameters using either the command line mode or the Java API it
provides. The following JSP code shows how to access Xalan from within a JSP and
then how to override a top-level parameter at runtime.
So the test would be self-contained, I've stored my XML and XSL inputs as strings.
These would normally be files outside the JSP code accessed via URLs or via file
reads.
In the XSL, you'll notice it has a top-level (that is, it is a direct child of the
xsl:stylesheet element) xsl:param named 'theParam'.
It's default value is a string 'the Default'. The stylesheet has a single match pattern
for the root of the test document and it outputs an HTML heading that echo's the
value of the 'theParam'.
After setting up the inputs to the Xalan processor, and just before doing the
transformation, there's is a call to xp.setStylesheetParameter(..). This sets the value
of the top level parameter 'theParam' to the new value 'the Override'. The processor
places the transformation result in a string and the JSP outputs this string to the
HTML output.
With this line, the output from the same stylesheet would be:
To run this test, install Xalan and add xalan.jar and xerces.jar to the classpath of
your jsp engine. Then put the jsp file below in the document space of the jsp engine.
Load the JSP on your browser and you should see the heading above.
XSLTProcessor xp = null;
try {
xp = XSLTProcessorFactory.getProcessor();
} catch ( Exception e ) {
%><h1>Unable to obtain processor</h1>
<%=e%><%
}
Another solution
Author: Paul Flinton (http://www.jguru.com/guru/viewbio.jsp?EID=423606), Jan 24,
2002
You can also do this:
In the jsp file...
<xsl:style xml='foo.xml' xsl='fooStyle.xsl'>
<xsl:param name='param1' value='<%="theValue">'/>
</xsl:style>
However, you must pass an object in the value attribute of the param tag.
It seems to be not there anywhere. Check out this site for industry based XML
initiatives by particular industry related groups.
I'm trying to output an XmlDocument from the HttpServlet's response
object to another servlet.Code below:
The technique I've seen used is to convert the binary file (any type) into Base64.
This converts every three binary bytes into a four-character ascii string. The file
encoded in this fashion is therefore only 25% bigger than the original file. And its
relatively easy to encode and decode.
The ascii characters used by the encoding are all valid XML text node characters so
you don't even need to use CDATA sections. You can simply place the encoded result
inside an element and the file will be well-formed. The encoding is described by RFCs
1421 and RFC 2045.
The W3C has a Java tool for encoding and decoding base64 which is part of their
DSig project.
See http://www.w3.org/PICS/refcode/Parser/javadocs/Package-w3c.tools.codec.html
for the API and http://www.w3.org/PICS/refcode/Parser/ for information about
obtaining the tools.
Mulberry Technologies runs the XSL-list mailing list. Subscription information and
archives are available from their website.
What are some examples of sites which are purely developed in XML and
XSL?
Location: http://www.jguru.com/faq/view.jsp?EID=216194
Created: Sep 26, 2000 Modified: 2000-09-28 07:40:24.808
Author: Davanum Srinivas (http://www.jguru.com/guru/viewbio.jsp?EID=2011)
Question originally posed by Srinivas Thutika
(http://www.jguru.com/guru/viewbio.jsp?EID=46992
WebSites typically use Publishing Frameworks like the Open-Source framework from
Apache named Cocoon.
http://xml.apache.org/cocoon
http://xml.apache.org/cocoon/livesites.html
I have a document and almost all of the content is in HTML format. It is then
"translated" into an XML-like format by using JCDS. The problem with this
XML-like format is that it contains extraneous tags that hamper the feed
from coming in cleanly and complete. I was wondering if there is any code
or program out there to help me in order to "escape out" these stray tags.
Location: http://www.jguru.com/faq/view.jsp?EID=221520
Created: Oct 3, 2000 Modified: 2000-10-03 09:54:14.178
Author: Software Framework (http://www.jguru.com/guru/viewbio.jsp?EID=61156)
Question originally posed by Javad Shakib
(http://www.jguru.com/guru/viewbio.jsp?EID=112540
If the resulting XML document is well-formed you can use XSLT to "translate" it. See
http://metalab.unc.edu/xml/books/bible/updates/14.html for a relatively quick
explanation of XSLT. You can download a translator at
http://xml.apache.org/xalan/getstarted.html#download.
If the tags are simple enough, you can write a script or program to remove them. For
example:
The answer depends upon the structure of the data to be synchronized. Do both the
sides have same data structure? or is there significant difference in the data
structure? For example, different table structure, data types etc.
XML can be used in any data transfer and synchronization. I am synchronizing data
between an SQL server and an Oracle database. The use of XML is more appropriate
if there is significant difference in the database schema and the way the data is
represented between the two sides. Using the XSLT and style sheets it is easy to
process and manipulate the data. But, handling the data through the utility is also a
complex process. While there are good JDBC drivers and libraries available for an
Oracle database, I am not aware if there are good drivers for Access database.
Moreover, the Access database does not support the standard SQL.
Write a data exporter and importer for Oracle side. The applications will connect
to the database using the JDBC drivers, and export/import data in/from XML files.
Oracle XML libraries will be useful here.
Do the transformations using an XSLT processor, such as xalan from Apache.
Import/export data on the Access database side. JDBC/ODBC driver may be
useful. I have no exoperience with XML libraries for Access data, so can not answer
this portion in detail.
If the database schema, or some of the table structures are same, it is better to use
ODBC drivers to connect the client and the server to synchronize the data. In this
case the possible steps would be:
Establish the connection to the Oracle database using the ODBC from the client
side.
Map the tables from oracle database in the Access database using the remote
connection.
Create queries to update/delete data.
What is XSP?
Location: http://www.jguru.com/faq/view.jsp?EID=223224
Created: Oct 5, 2000 Modified: 2000-11-09 11:08:06.645
Author: K V R K Varma (http://www.jguru.com/guru/viewbio.jsp?EID=223223)
Just as Java is aimed at providing a clear separation of content from application and
business logic, XSP seek to provide the same for XML- based applications. Although
many of the currently available XML frameworks allow this separation of layers within
complied code, changes to the formatting of actual data in an XML document still
requires Java code and subsequent recompilation.
What is PI ?
Location: http://www.jguru.com/faq/view.jsp?EID=223225
Created: Oct 5, 2000 Modified: 2000-10-10 13:37:59.539
Author: K V R K Varma (http://www.jguru.com/guru/viewbio.jsp?EID=223223)
What is a DTD ?
Location: http://www.jguru.com/faq/view.jsp?EID=223227
Created: Oct 5, 2000 Modified: 2000-10-10 13:40:56.286
Author: K V R K Varma (http://www.jguru.com/guru/viewbio.jsp?EID=223223)
What is XPath?
Location: http://www.jguru.com/faq/view.jsp?EID=223228
Created: Oct 5, 2000 Modified: 2000-10-10 13:43:55.447
Author: K V R K Varma (http://www.jguru.com/guru/viewbio.jsp?EID=223223)
The XPath(XML Path Language) specification defines how a specific item within an
XML document can be located. It is used extensively with XSLT. This is done by
referencing specific nodes in the XML document. For example:
<JavaXML:Printer>
.
.
<JavaXML:Parts>
</JavaXML:Parts>
<JavaXML:Company> HP </JavaXML:Company>
</JavaXML:Printer>
What is XQL?
Location: http://www.jguru.com/faq/view.jsp?EID=223231
Created: Oct 5, 2000 Modified: 2000-11-08 07:56:39.673
Author: K V R K Varma (http://www.jguru.com/guru/viewbio.jsp?EID=223223)
What is SAX?
Location: http://www.jguru.com/faq/view.jsp?EID=223233
Created: Oct 5, 2000 Modified: 2000-10-16 08:12:31.607
Author: K V R K Varma (http://www.jguru.com/guru/viewbio.jsp?EID=223223)
SAX, or SimpleAPI for XML, provides a framework for parsing XML data.
SAX define events which applications can be notified of during the parsing process.
What is JAXP?
Location: http://www.jguru.com/faq/view.jsp?EID=223234
Created: Oct 5, 2000 Modified: 2000-10-10 13:51:17.357
Author: K V R K Varma (http://www.jguru.com/guru/viewbio.jsp?EID=223223)
JAXP(Java API for XML Parsing), does not redefine SAX or DOM but ensures that all
XML-Conformant parsers can be accessed within the Java applications through a
standard pluggable layer.
These three API's (JAXP, SAX and DOM) make up the Java Developers toolkit for
handling XML.
A complete JAXP reference is available here.
Java and XML make a good pair because Java provides portable code and XML
provides portable data. Java code can run on any OS and hardware platform with a
Java Virtual Machine. In addition, Java provides the most robust set of API's, parsers,
processors and tools for XML. Both Java and XML have limitations if taken separately.
In Java the developer has to handle network data formats. JavaServer Pages do not
provide a real separation of content and presentation layers. XML tools handle these
tasks for Java.
I want to generate a nice report using XML & XSL. From this schema
<RECORDSET>
<RECORD><CUST>Cust 1</CUST><VALUE>1</VALUE></RECORD>
<RECORD><CUST>Cust 1</CUST><VALUE>2</VALUE></RECORD>
<RECORD><CUST>Cust 2</CUST><VALUE>3</VALUE></RECORD>
<RECORD><CUST>Cust 2</CUST><VALUE>4</VALUE></RECORD>
<RECORD><CUST>Cust 3</CUST><VALUE>5</VALUE></RECORD>
<RECORD><CUST>Cust 3</CUST><VALUE>6</VALUE></RECORD>
</RECORDSET>
I want to generate a report that looks like this
<table>
<tr><td>Cust 1</td><td>1</td></tr>
<tr><td> </td><td>2</td></tr>
<tr><td>Cust 2</td><td>3</td></tr>
<tr><td> </td><td>4</td></tr>
<tr><td>Cust 3</td><td>5</td></tr>
<tr><td> </td><td>6</td></tr>
</table>
The following stylesheet output rows of customer records in a table where the
customer name is displayed in column 1 in only the first record for a given customer.
It uses the preceding::RECORD axis in the comparison, which gathers all of the
RECORDs before the current RECORD being processed in the for-each loop. The
[last()-1] predicate on the test gets the last one of these.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="RECORDSET">
<table border="1">
<xsl:for-each select="RECORD">
<tr>
<xsl:choose>
<!-- If it's the first record, fill in column 1 -->
<xsl:when test="position()=1">
<td><xsl:value-of select="CUST"/></td>
</xsl:when>
<!-- If the last preceding record has a different
customer, fill in column 1 -->
<xsl:when test="preceding::RECORD[last()-1] and
string(preceding::RECORD[last()-1]/CUST)!=string(CUST)">
<td><xsl:value-of select="CUST"/></td>
</xsl:when>
<!-- Otherwise its the same customer, output an empty
cell in column 1 -->
<xsl:otherwise>
<td></td>
</xsl:otherwise>
</xsl:choose>
<td><xsl:value-of select="VALUE"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
Given the example test data, the table produced looks like:
Cust 1 1
2
Cust 2 3
4
Cust 3 5
6
CDATA is short for character data, and PCDATA is short for parsed character data. It
is important when handling data that contains markup that a parser would other
think as a tag or some other command instead of just data for a particular element.
Does DOM include APIs for diffing and merging XML documents?
Location: http://www.jguru.com/faq/view.jsp?EID=229569
Created: Oct 16, 2000 Modified: 2000-10-23 09:25:52.436
Author: Serge Knystautas (http://www.jguru.com/guru/viewbio.jsp?EID=100012)
Question originally posed by dylan taffe
(http://www.jguru.com/guru/viewbio.jsp?EID=93678
The DOM API does not support diff and merge, although IBM Alphaworks has a Java
tool named xmldiffmerge which you can use for just this purpose.
DTDs do not allow you to specify possible values of data, either for attributes or
elements. It basically only allows you to specify how elements nest and their
attributes.
Are there any tools to support development of XML-based JSP pages, such
as:
<community>
<name-label>Name</name-label>
<name>
<jsp:expression>
community.getName()
</jsp:expression>
</name>
<description-label>Description</description-label>
<description>
<jsp:expression>
community.getDescription()
</jsp:expression>
</description>
<admin-label>Community Administrator</admin-label>
<admin>
<jsp:expression>
community.getAdministrator()
</jsp:expression>
</admin>
</community>
Location: http://www.jguru.com/faq/view.jsp?EID=229571
Created: Oct 16, 2000 Modified: 2000-11-08 08:38:33.556
Author: Serge Knystautas (http://www.jguru.com/guru/viewbio.jsp?EID=100012)
Question originally posed by Mark Lorenz
(http://www.jguru.com/guru/viewbio.jsp?EID=118221
The Cocoon project by the Apache Group is doing something very similar to this.
They call their files XSP instead of JSP as the syntax is different, and they also
leverage some of the flexibility that an XML based publishing system will give you.
Check out the Cocoon web site.
I want to create a Java program that will read an XML file and extract the
information I specify. My question is, what is the best method to read nodes
and extract information out of an XML document whose type is not known
beforehand?
Location: http://www.jguru.com/faq/view.jsp?EID=229580
Created: Oct 16, 2000 Modified: 2000-11-07 13:48:52.92
Author: Serge Knystautas (http://www.jguru.com/guru/viewbio.jsp?EID=100012)
Question originally posed by Rahul Khanna
(http://www.jguru.com/guru/viewbio.jsp?EID=201072
SAX is very simple API to handle extracting information from an XML file. You
register your class to the SAX parser as a listener of "SAX events", which are just
when the parser hits certain different parts of the file. You will get calls when a tag is
started, when a tag stops, and the character data within the tag. In each of these
situations, the event will contain information about what tag was started or stopped
and any attributes of that tag.
Try downloading the XercesJ parser from http://xml.apache.org/ and trying some of
the SAX examples.
EDI stands for Electronic Data Interchange. It is form of electronic communication for
interchanging bussiness data (orders, payments etc.) It uses data format that is very
unsimilar to XML so it cannot be implemented in XML.
Are there any sites that provide more information or example source code
for Apache's Xerces-J and the DOM?
Location: http://www.jguru.com/faq/view.jsp?EID=231984
Created: Oct 19, 2000 Modified: 2000-10-20 08:08:35.967
Author: krtek veliky (http://www.jguru.com/guru/viewbio.jsp?EID=230084)
Question originally posed by Radhakrishnan R.A.V.
(http://www.jguru.com/guru/viewbio.jsp?EID=10157
Some examples come with Xerces. You can read about them at
xml.apache.org/xerces-j/samples.html
Use xerces parser from apache. You should use the XMLSerializer class to serialise
dom to xml file. Here is code sniplet.
// import following package
import org.apache.xml.serialize.*;
OutputFormat of =
new OutputFormat("XML","UTF-8",true);
XMLSerializer serializer =
new XMLSerializer();
serializer.setOutputFormat(of);
serializer.setOutputstream(new
FileOutputstream("xmlfile.xml"));
serializer.serialize(dom);
You can get the xerces parser from Apache.
Comments and alternative answers
You can also use the Java project X classes. Down load...
Author: Mafaz Zafar (http://www.jguru.com/guru/viewbio.jsp?EID=234259), Oct 23,
2000
You can also use the Java project X classes. Down load Java Project X Technology
Release 2 from this site. The XmlDocument class has a few write methods. You can
use one of these methods to write DOM to an output stream. You have to import the
appropriate classes in your code.
The following lines of code are from one of the methods we wrote.
fileOutputStream.close();
Re: You can also use the Java project X classes. Down load...
Author: Christophe Demez
(http://www.jguru.com/guru/viewbio.jsp?EID=397288), Sep 5, 2001
Yes, but ...
In the example you give, it will write an empty file, because "doc" is empty.
Thanks
Re: Re: You can also use the Java project X classes. Down load...
Author: Mafaz Zafar (http://www.jguru.com/guru/viewbio.jsp?EID=234259),
Sep 7, 2001
It depends how you create the document.
We have written a class which has a bunch of methods in it for creating XML
documents. It can load existing XML documents and search for elements and
attributes. It can add elements and attributes to newly created XML document.
It can load existing XML documents. It can save XML documents to files etc
etc. It is making use of Java Project X Technology Release 2
Here is some of the code from our class which we wrote to process XML
documents.
import java.io.File;
//import com.ccccccccc.exception.ExceptionMethod;
import com.sun.xml.parser.Resolver;
import com.sun.xml.tree.*;
import org.xml.sax.InputSource;
import java.io.*;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.w3c.dom.*;
import java.util.*;
// VARIABLES
public XMLManager(){
this.super();
this.super();
if (root != null) {
this.doc = document;
try {
root = doc.getDocumentElement();
root.normalize();
throw new Exception("** Parsing error" + ", line " + err.getLineNumber () + ",
uri " + err.getSystemId () + " " + err.getMessage ());
catch (SAXException e) {
Node replacedNode;
try {
loadXML(TEMPLATE_FILE);
}
catch (IOException ioe) {
throw ioe;
throw em;
//LOCAL VARIABLES
XmlDocumentBuilder xmlDocumentBuilder;
ElementEx elementEx;
DocumentType docType;
// Create document
doc = xmlDocumentBuilder.createDocument();
// Create Root
root = doc.createElementEx(rootName);
doc.appendChild(root);
//Note: selected file is the full path and name of the file where the XML should
be stored. (examlpe: "c:\\temp\\myXmlfile.xml")
int index = 0;
FileOutputStream fileOutputStream;
//If selectedFile does not have any extension add .xml as extension.
index = selectedFile.lastIndexOf(".");
if (index == -1) {
this.saveXML(fileOutputStream);
doc.write(outputStream);
// Closes this output stream and releases any system resources //associated with
this stream.
outputStream.close();
this.loadXML((InputStream)fileInputStream);
/* NOTE: The following method can load XML from an input stream. If you
have XML in form of a string it has to be converted to an input stream first*/
/*NOTE: This method validates the XML when it loads it. If you do not want
it to be validated just change the code and pass false as mentioned in the
code*/
try {
root = doc.getDocumentElement();
root.normalize();
throw new Exception("** Parsing error" + ", line " + err.getLineNumber () + ",
uri " + err.getSystemId () + " " + err.getMessage ());
catch (SAXException e) {
return root.getElementsByTagName(tagName);
Once the document is created with the specified root name we can add
elements and node to the newly created document. We have several other
methods in our code to add elements and attributes and nodes to the XML
document. /*Note: If you do not know how to convert a string which
represents your XML to a input stream use the following code as example.*/
/*NOTE: XMLManager is our class which we wrote which contains all the
above mentioned methods.*/
inputByte = responseXml.getBytes();
xmlManager.loadXML((InputStream)outputStream);
Re: Re: Re: You can also use the Java project X classes. Down load...
Author: Christophe Demez
(http://www.jguru.com/guru/viewbio.jsp?EID=397288), Sep 10, 2001
Thanks, Really good ! Do you know that you use some depreceated methods (
like createXmlDocument ). Have you solve this problem ? Thanks Christophe
My solution
Author: Andrew Russell (http://www.jguru.com/guru/viewbio.jsp?EID=508552), Feb
22, 2004
My solution to this problem was to delete a spurious space in one of my tags.
i.e. <invoice-file att1="eeerrr" ...
changed to <invoice-file att1="eeerrr" ...
And that was it. Andrew.
I have to build an XML document from pieces of existing ones, and then
output it as a string. What libraries should I use?
Location: http://www.jguru.com/faq/view.jsp?EID=233260
Created: Oct 21, 2000 Modified: 2000-11-04 20:54:29.121
Author: Pramod Hirole (http://www.jguru.com/guru/viewbio.jsp?EID=41443)
Question originally posed by Stéphane Félix
(http://www.jguru.com/guru/viewbio.jsp?EID=210800
If you have pieces of existing valid documents as nodes then you can import those
into the document you want to build by appending those nodes as child elements to
the document.
document.importNode(doc1Elm);
document.importNode(doc2Elm);
document.appendchild(doc1Elm);
docElm1.appendChild(docElm2);
To write document object as a string you need to serialize it. You can use the Apache
Xerces parser available from Apache. You should use XMLSerializer class to serialise
document as String. Here is code sniplet.
// import following package
import org.apache.xml.serialize.*;
OutputFormat of =
new OutputFormat("XML","UTF-8",true);
XMLSerializer serializer =
new XMLSerializer();
ByteArrayOutputStream baos =
new ByteArrayOutputstream()
serializer.setOutputFormat(of);
serializer.setOutputstream(baos);
serializer.serialize(document);
String domstr =
new String(baos.toByteArray())
I have to build an XML document from pieces of existing ones, and then
output it as a string. What libraries should I use?
Location: http://www.jguru.com/faq/view.jsp?EID=233959
Created: Oct 23, 2000 Modified: 2000-11-07 12:04:25.629
Author: bob mcwhirter (http://www.jguru.com/guru/viewbio.jsp?EID=41649)
Question originally posed by Stéphane Félix
(http://www.jguru.com/guru/viewbio.jsp?EID=210800
To programatically assemble an XML document, I'd scan in each document you wish
to use as sources, with either DOM, or my favorite, JDOM.
Once you have the documents in a DOM/JDOM tree, you can rather easily pull out
the portions you want, and reconstruct a new document containing the desired
subtrees from the source documents.
While DOM is the 'standard', I find JDOM more useful for the Java programmer for
manipulating XML documents as a structure, instead of a stream of bytes.
I have some data and I want to use next and previous buttons to display
each record. I can accomplish this at the client by using
xmldocument.recordset.moveNext() in a JavaScript event. But how can I
accomplish this when I am using XSL?
Location: http://www.jguru.com/faq/view.jsp?EID=235044
Created: Oct 24, 2000 Modified: 2000-11-07 13:44:34.982
Author: Alexandre Cuva (http://www.jguru.com/guru/viewbio.jsp?EID=235041)
Question originally posed by vishnu agrawal
(http://www.jguru.com/guru/viewbio.jsp?EID=228066
2)[DataBiding] Add the following statement at the start of the page right after the
body:
<XML SRC="budgetGet.xml" ID="xmldso"></XML>
and then use like before the xmldso.recordset.moveNext()
The first version gives you a way to navigate complex XML documents.
You can find some good source code examples at the Wrox site.
I am looking for a tool to query a DTD. I know IBM's XML4J does it. Anyone
heard of another tool?
Location: http://www.jguru.com/faq/view.jsp?EID=241219
Created: Oct 31, 2000 Modified: 2000-11-07 14:36:13.935
Author: Mark Pollack (http://www.jguru.com/guru/viewbio.jsp?EID=231174)
Question originally posed by Gregory Van Ass
(http://www.jguru.com/guru/viewbio.jsp?EID=34607
The XML parser from Oracle lets you access the parsed DTD with the class
oracle.xml.parser.v2.DTD
I am trying to build an XML Document with the DOM that can be parsed from
Xalan XSL Processor.
But when creating the document with DOM I get following error message :
<document>
<title>Simple PDF Example</title>
<author>Holger Prause</author>
<note>The following text was taken from the FO Example File
readme.fo</note>
<content>Some text</content>
</document>
Why is the DOM creating the document with the default Encoding Cp1252?
How can I set the encoding to "UTF-8"?
Location: http://www.jguru.com/faq/view.jsp?EID=243588
Created: Nov 2, 2000 Modified: 2000-11-07 12:10:57.093
Author: Davanum Srinivas (http://www.jguru.com/guru/viewbio.jsp?EID=2011)
Question originally posed by Holger Prause
(http://www.jguru.com/guru/viewbio.jsp?EID=224969
Use
<?xml version="1.0" encoding="UTF-8" ?>
instead of
<?xml version="1.0" encoding="Cp1252"?>
Comments and alternative answers
This comment is specifically for using the Apache crimson implementation of JAXP.
• public void write (OutputStream out) - has the encoding hard coded to
"UTF8".
• public void write (Writer out) - uses the system value for encoding.
• public void write (Writer out, String encoding) - inserts the value of the
encoding argument directly into the output.
See the article How do I set a default character encoding for file I/O operations, JDBC
requests and so on? for info on how to change your encoding at the JVM level.
http://lempinen.net/sami/jtidy/
<xsl:template match="text()">
MATCH: <xsl:value-of select="."/></xsl:template>
If you need formating then I guess it is better to output HTML. If you really need
pure text output then use the JavaScript extension in XSLT and format your text in
JavaScript.
Using both Sun's and Apache's(Xerces) implentations of the SAX XML paser,
it appears that it requires over 7 MEGS of heap space to parse a 150 kilobyte
XML document. I can understand a DOM parser having this kind of footprint,
but why would a Java SAX parser need such an absurd amount of memory?
Location: http://www.jguru.com/faq/view.jsp?EID=248646
Created: Nov 8, 2000 Modified: 2000-11-09 10:54:18.403
Author: Serge Knystautas (http://www.jguru.com/guru/viewbio.jsp?EID=100012)
Question originally posed by J Majik
(http://www.jguru.com/guru/viewbio.jsp?EID=61152
When writing software, you have three areas you have to try to balance... speed,
memory usage, and size of code. These commercial parsers are generally optimized
purely for performance and require a lot of overhead. Also, assuming they make
extensive use of Strings, in Java this creates a lot of object overhead.
There are XML parsers out there that are optimized for a smaller code footprint and
less memory overhead including MinML at http://www.wilson.co.uk/xml/minml.htm
and NanoXML at http://nanoxml.sourceforge.net/.
The xerces parser does not like XML data containing tags e.g. <start> <--
xml data starts--> <html><head><title>Xmldata
</title></head></html> <--xml data ends--> </start> Is there a way to
parse/store that information without confusing the parser?
Location: http://www.jguru.com/faq/view.jsp?EID=248650
Created: Nov 8, 2000 Modified: 2000-11-08 11:20:27.884
Author: Serge Knystautas (http://www.jguru.com/guru/viewbio.jsp?EID=100012)
Question originally posed by Kedar Aras
(http://www.jguru.com/guru/viewbio.jsp?EID=80325
Data such as <!-- --> and other tags you do not wish to become part of the XML tag
scheme should be properly encoded. Convert & to &, convert < to <, and
convert > to >.
Schema
<element name="request">
<complexType>
<element ref="authentication" minOccurs='0' maxOccurs='1'/>
<element ref="application" minOccurs='0' maxOccurs='1'/>
</complexType>
</element>
DTD
<ELEMENT request (authentication | application)>
Location: http://www.jguru.com/faq/view.jsp?EID=248864
Created: Nov 8, 2000 Modified: 2000-11-09 10:46:06.426
Author: Dane Foster (http://www.jguru.com/guru/viewbio.jsp?EID=228595)
Question originally posed by Stefan Lecho
(http://www.jguru.com/guru/viewbio.jsp?EID=32509
Please note: I'm using the Schema language as specified by the current W3C
Candidate recommendation (...2000/10/XMLSchema).
<xsd:element name="request">
<xsd:complexType>
<xsd:choice>
<xsd:element ref="authentication" minOccurs="0" maxOccurs="1"/>
<xsd:element ref="application" minOccurs="0" maxOccurs="1"/>
</xsd:choice>
</xsd:complexType>
</xsd:element>
Is there an interface for working with an XML file directly. From SUN's
technical tips, I know that I can write the whole XML Document to a file.
That is not very efficient if all I want to do is modify an element within an
XML file.
Location: http://www.jguru.com/faq/view.jsp?EID=248869
Created: Nov 8, 2000 Modified: 2000-11-09 10:50:05.244
Author: Dane Foster (http://www.jguru.com/guru/viewbio.jsp?EID=228595)
Question originally posed by Hoi Fai Leung
(http://www.jguru.com/guru/viewbio.jsp?EID=207210
The Document Object Model (DOM). You can find the specification here. Xerces form
Apache supports DOM Level 1 and DOM Level 2
Yes. That's what XSLT is all about. Check out the specification. There are also tons of
resources on the web that show how to do this, including xml.com
I have to interface 3rd party applications having data in XML format with my
site. I am currently using JSPs and EJBs for my site. How can I take the
instream data (XML format - text) , convert it to an object (DOM/SAX) and
call it from my JSP page. Similarly how do I convert an object back into the
XML format and send it across to the third party, providing an XML interface.
I know the DTDs of the 3rd party applications.
Location: http://www.jguru.com/faq/view.jsp?EID=249891
Created: Nov 9, 2000 Modified: 2000-11-09 11:04:38.758
Author: Bruce Martin (http://www.jguru.com/guru/viewbio.jsp?EID=12) Question
originally posed by Loveen Advani
(http://www.jguru.com/guru/viewbio.jsp?EID=27396
Simply invoke an XML parser on the server passing it the incoming XML stream. The
parser will produce DOM objects or you can register for SAX events if you prefer an
event based parse. Once you have DOM or SAX access to the XML on the server, you
can process it as needed.
To return XML, you can write XML directly in your Java code to your output stream or
you can create DOM objects and then ask the DOM to write it to your stream.
For rendering of static data you can probably apply XSL stylesheets on the XML
content files stored on your Web Server. These XSL files can generate HTML or WML
depending on where the response has to be sent. For dymanic content you can pull
out enterprise data or data from a B2B transaction data and generate XML on the fly.
You can still use the XSL stylesheets to send the data to different clients.
How you do it is entirely dependent on the requirements of the application but you
should still utilize the MVC pattern of web application design. So in this case your
JavaBeans/session beans will contain the XML data (static or dynamic) which has to
be rendered, JSP will be the view used to generate/render that data on the client and
servlets as an interaction controller. EJB's are required if the application is highly
transaction oriented.
How can I make a string appear as it is when retrieved from XML? For
example, string a b c should appear as it is and not a+b+c.
Location: http://www.jguru.com/faq/view.jsp?EID=250744
Created: Nov 10, 2000 Modified: 2000-11-13 08:10:59.283
Author: Surendra Chauhan (http://www.jguru.com/guru/viewbio.jsp?EID=45993)
Question originally posed by Rajesh C
(http://www.jguru.com/guru/viewbio.jsp?EID=45707
A string will appear as it is if you use the right character code for example UTF-8
supported by the operating system and the application.
When you write to an XML file, use the character code the application which is
reading the file is supporting.
How can I generate an XML document from a relational database? This XML
should be in the format specified by a particular DTD.
Location: http://www.jguru.com/faq/view.jsp?EID=251541
Created: Nov 11, 2000 Modified: 2000-11-13 08:07:52.357
Author: Dieter Wimberger (http://www.jguru.com/guru/viewbio.jsp?EID=25708)
Question originally posed by Srinath Mani
(http://www.jguru.com/guru/viewbio.jsp?EID=230075
Well you can either code it by hand, retrieving the values from the database and
writing out an XML file according to the DTD, or you can search for a tool that helps
you to do it. I would suggest to take a look at Castor (http://castor.exolab.org) which
could serve well for this task.
Comments and alternative answers
I have written an XML file (test.xml) and an XSLT stylesheet for WML 9test-
wml.xsl). I am trying to combine them with Cocoon. While using the Nokia
WAP Tollkit 2.0 to load the test.xml file I get the error message "Error.
Server returned unsupported content type: text/html" Can anybody help
me? I have to say that I am running the Apache web server and I have
configured it with all the relevant MIME types.
Location: http://www.jguru.com/faq/view.jsp?EID=251542
Created: Nov 11, 2000 Modified: 2000-11-13 08:08:46.563
Author: Dieter Wimberger (http://www.jguru.com/guru/viewbio.jsp?EID=25708)
Question originally posed by Panos Konstantinidis
(http://www.jguru.com/guru/viewbio.jsp?EID=242435
XSLT stands for Extensible Stylesheet Language Transformations. For more on what
XSLT is, see another FAQ.
What is SVG?
Location: http://www.jguru.com/faq/view.jsp?EID=270704
Created: Dec 6, 2000 Modified: 2000-12-06 08:46:11.44
Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7)
The W3C maintains a list of viewers. Just grab one like the Adobe or Java-based
Jackaroo viewer.
Comments and alternative answers
Batik, which is open source and part of the Apache project, is written in Java, and includes an SVG
generator and viewer.
It also includes a Swing component called JSVGCanvas which could be added to an applet.
I think the Batik team are also about to include direct support for SVGs in Mozilla.
The above statement is for Korean. The Java stream class can be set to some other
character set in its constructor.
Is there a doclet for generating XML output from javadoc comments?
Location: http://www.jguru.com/faq/view.jsp?EID=272527
Created: Dec 8, 2000 Modified: 2000-12-11 09:32:18.561
Author: David Hainlin (http://www.jguru.com/guru/viewbio.jsp?EID=272526)
Question originally posed by John Zukowski PREMIUM
(http://www.jguru.com/guru/viewbio.jsp?EID=7
There is a doclet called JDox which produces a single XML file from a single javadoc
session. Additional info can be found at the JDox Home.
XHTML is well formed XML, according to the spec. As such you should be able to use
a XSLT Java API and a stylesheet to transform XHTML to the XML you want.
The Java part of such an app would be minimal -- just enough to open the XML docs
and apply the XSLT to it. Kay's work includes a standard API for this which abstracts
the XSLT engine. I think saxon and xt include apps that already do this.
Is there a tool to generate a sample XML file from a given valid DTD or
schema?
Location: http://www.jguru.com/faq/view.jsp?EID=277288
Created: Dec 13, 2000 Modified: 2000-12-14 10:14:32.576
Author: Darius Kasad (http://www.jguru.com/guru/viewbio.jsp?EID=45296)
Question originally posed by p shah
(http://www.jguru.com/guru/viewbio.jsp?EID=255775
What are good, open-sourced, SGML to XML translators or Java based SGML
parsers?
Location: http://www.jguru.com/faq/view.jsp?EID=277317
Created: Dec 13, 2000 Modified: 2000-12-14 10:15:34.495
Author: John Dahle (http://www.jguru.com/guru/viewbio.jsp?EID=75944) Question
originally posed by John Dahle
(http://www.jguru.com/guru/viewbio.jsp?EID=75944
I have discovered a work around that I thought I might share with you all. I was able
to parse SGML by adding end tags to each open SGML tag and parsing it using a
conventional XML parser. It's not pretty, but it worked.
I am using IBM XML Parser 2.0.16. I am parsing an XML document that has
no DTD. But my parser is giving errors related to DTD. How can I parse XML
without DTD?
Location: http://www.jguru.com/faq/view.jsp?EID=283611
Created: Dec 21, 2000 Modified: 2000-12-22 11:06:42.601
Author: Ibrahim Levent (http://www.jguru.com/guru/viewbio.jsp?EID=131172)
Question originally posed by Ibrahim Levent
(http://www.jguru.com/guru/viewbio.jsp?EID=131172
You can't parse because this version is not providing any support for this kind of
parsing. Validity is one of the most important issue in XML structure. Validation is
based on internal or external DTD. If you do not consider validation, you can parse
yourself in your code without needing any XML parser. There are many tools that
checks if your XML is well-formed or valid. You can use these tools.
Comments and alternative answers
Are there any GUI editors which would ease the creation of an XSL file for
using it with FO (flow objects for PDF, CSS etc.. ) ?
Location: http://www.jguru.com/faq/view.jsp?EID=283634
Created: Dec 21, 2000 Modified: 2000-12-22 11:01:12.98
Author: Ibrahim Levent (http://www.jguru.com/guru/viewbio.jsp?EID=131172)
Question originally posed by piyush sheth
(http://www.jguru.com/guru/viewbio.jsp?EID=38282
These may help you : http://www.unicorn-enterprises.com/,
http://xml.apache.org/fop/, http://www.antennahouse.com/xslformatter.html ,
http://www.esng.dibe.unige.it/REXP , http://www.renderx.com/FO2PDF.html
Is there some API using which I can modify a very large XML file? DOM goes
out of memory and SAX just doesn't fit the bill.
Location: http://www.jguru.com/faq/view.jsp?EID=285686
Created: Dec 25, 2000 Modified: 2001-01-02 08:26:48.3
Author: Chandra Patni (http://www.jguru.com/guru/viewbio.jsp?EID=33585)
Question originally posed by Mohit Khurana
(http://www.jguru.com/guru/viewbio.jsp?EID=119823
One of the upcoming polular API for XML parsing is JDOM (www.jdom.org). It is a
sort of hybrid approach between DOM and SAX. JDOM API lets you use either DOM or
SAX parser under the hood and uses the power of Java collection API which makes
XML parsing a lot more easier. JDOM also let's you create your own XML document
from scratch and modify original XML document by using either SAX or DOM API
under the covers. JDOM API's SAXBuilder class is probably fits the bill for parsing a
very large XML document which uses SAX API for parsing and allows you to modify
the document at the same time.
XML.COM's Hello, Voice World has an example using IBM's alphaWorks voiceXML
interpreter. One more example is at An Introduction To VoiceXML.
Comments and alternative answers
How can I use an IMG tag for including images in XSL stylesheets?
Location: http://www.jguru.com/faq/view.jsp?EID=286361
Created: Dec 26, 2000 Modified: 2001-01-02 17:58:41.159
Author: Davanum Srinivas (http://www.jguru.com/guru/viewbio.jsp?EID=2011)
Question originally posed by Monica gupta
(http://www.jguru.com/guru/viewbio.jsp?EID=263610
Is there some API using which I can modify a very large XML file? DOM goes
out of memory and SAX just doesn't fit the bill.
Location: http://www.jguru.com/faq/view.jsp?EID=287455
Created: Dec 27, 2000 Modified: 2001-01-08 08:33:40.19
Author: Rishi Prakash (http://www.jguru.com/guru/viewbio.jsp?EID=62455)
Question originally posed by Mohit Khurana
(http://www.jguru.com/guru/viewbio.jsp?EID=119823
What do I need in order to use the msxml.dll parser from IE5 if the IE5 is
not installed on the target system? Our software uses the IE XML parser for
export of data in XML format, but some users do not want to be dependent
on IE to run our software. This has lead to some problems, since the parser
does not appear to work without a complete installation of IE5. What DLLs
need to be included in the installation kit for for the parser to work without
IE? Alternatively what kind of minimum custom installation of IE is needed?
Is there a better well documented XML parser available to use in a WINNT
4.0/Win2000 environment that is not browser dependent?
Location: http://www.jguru.com/faq/view.jsp?EID=288439
Created: Dec 28, 2000 Modified: 2001-01-08 08:31:20.221
Author: Kulwant S. Bhatia (http://www.jguru.com/guru/viewbio.jsp?EID=62359)
Question originally posed by Erik S
(http://www.jguru.com/guru/viewbio.jsp?EID=281605
I've had similar problems. The MSXML parser will only work either with IE5 installed
or ADO2.5 libraries installed which Microsoft didn't bother to document. If you don't
have the DLLs you can download them from the Microsoft site. I'm currently using
Xerces for my XML parsing and the documentation is excellent. Check out
xml.apache.com.
How can I serialize and de-serialize an XML Node? For example to transfer a
Node object over TCP?
Location: http://www.jguru.com/faq/view.jsp?EID=290154
Created: Dec 31, 2000 Modified: 2001-01-02 18:02:07.461
Author: Davanum Srinivas (http://www.jguru.com/guru/viewbio.jsp?EID=2011)
Question originally posed by Dan Corkum
(http://www.jguru.com/guru/viewbio.jsp?EID=85224
DOM API is not really geared towards serialization/de-serialization. Try JDOM from
http://www.jdom.org/. It has adapters to work with existing DOM documents. A lot
of classes implement java.io.Serializable and java.lang.Cloneable interfaces to make
coding easier.
Where can I find a simple Java example of creating an XML document and
saving it to a file?
Location: http://www.jguru.com/faq/view.jsp?EID=292249
Created: Jan 3, 2001 Modified: 2001-01-08 08:21:29.194
Author: Davanum Srinivas (http://www.jguru.com/guru/viewbio.jsp?EID=2011)
Question originally posed by Eric Chow
(http://www.jguru.com/guru/viewbio.jsp?EID=25181
The following example is an extract from Intro to JDOM by Elliotte Rusty Harold.
import java.io.*;
import org.w3c.dom.*;
import org.apache.xerces.dom.*;
import org.apache.xml.serialize.*;
try {
}
Comments and alternative answers
The DTD file should be placed in the default public_html or htdocs directory on the
webserver. This directory is the public folder where all the html and jsp pages, along
with other files that must be published to the client are placed. The DTD file can be
accessed in the XML script as shown below.
http://java.isavvix.com/forums/viewThread.jsp?forum=39&thread=541
The 1.0 VoiceXML DTD is available from the Voice XML Forum.
I want to parse an XML file stored on a remote server. Can I use the DOM
for the same without downloading the file?
Location: http://www.jguru.com/faq/view.jsp?EID=299965
Created: Jan 11, 2001 Modified: 2001-01-11 12:17:32.305
Author: Surendra Chauhan (http://www.jguru.com/guru/viewbio.jsp?EID=45993)
Question originally posed by Arti W
(http://www.jguru.com/guru/viewbio.jsp?EID=298558
You can use the DOM to parse the XML file without downloading the file from the
remote server. But you have to use the URL to access the file. Here is sample code.
import com.sun.xml.parser;
import com.sun.xml.tree;
import org.w3c.dom;
import org.xml.sax;
Location: http://www.jguru.com/faq/view.jsp?EID=301021
Created: Jan 12, 2001 Modified: 2001-01-12 11:26:21.985
Author: Surendra Chauhan (http://www.jguru.com/guru/viewbio.jsp?EID=45993)
Question originally posed by thulasireddy vakati
(http://www.jguru.com/guru/viewbio.jsp?EID=292782
They can be downloaded from Java Project X
This will include the xml-tr2.zip file. Unzip the file to a folder and include xml.jar in
the classpath for the Java installation on your machine.
XML data binding is a concept of generating Java classes (source code) from XML
schema languages. Objects of such generated classes may represent XML document
which validates against the schema. Such mapping of XML schema to Java classes
and XML data to Java objects is called XML data binding.
JSR 00031, also known as project Adelard provides specification of such facility. It is
done by providing by providing a schema in question and a data binding schema and
compiling them into Java source code. The generated code contains getters, setters
and methods for marshalling, unmarshalling and validation.
The Data binding schema can be used to fine-tune the class generation code. Adelard
provides provision for generating a default data binding schema from the schema in
question.
XML can be best described in three tier architecture as the portable data which can
be sent across the wire. XML can be thought of as data flowing between these tiers.
How can I validate an XML file with a schema using the Xerces parser?
Location: http://www.jguru.com/faq/view.jsp?EID=301682
Created: Jan 13, 2001 Modified: 2001-01-15 19:31:01.099
Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Question
originally posed by rahul bose
(http://www.jguru.com/guru/viewbio.jsp?EID=219615
Re:How can I validate an XML file with a schema using the Xerces parser?
Author: Arun Iyer (http://www.jguru.com/guru/viewbio.jsp?EID=457780), Jul 19,
2001
How can I validate the XML without specifying an internet address?
I want to develop a web site in XML. What software is required and where
can I find it?
Location: http://www.jguru.com/faq/view.jsp?EID=302114
Created: Jan 14, 2001 Modified: 2001-01-15 19:41:48.63
Author: Brian Ewins (http://www.jguru.com/guru/viewbio.jsp?EID=301660)
Question originally posed by yashwant bandla
(http://www.jguru.com/guru/viewbio.jsp?EID=299485
If you are asking how to develop a dynamic java-based website which uses XML and
stylesheets to produce HTML/WML/SVG etc, then you should look at:
xml.apache.org for the Xerces parser and the Xalan XSL-T engine;
Oracle Technet if you're building a site on top of Oracle (you can get their XSQL
servlet, its very easy to use) - or read this javaworld article if you're using a non-
Oracle DB
Producing useful translations from XML using XSL is half the battle. You should get
hold of the Mulberry reference cards, and I found that Neil Bradleys "The XSL
Companion" was a decent reference.
Finally you can't mention places to get XML tools without alphaworks - lots of IBM
stuff you can download, including an XSL editor.
What is XLink?
Location: http://www.jguru.com/faq/view.jsp?EID=302116
Created: Jan 14, 2001 Modified: 2001-01-15 19:37:45.076
Author: Brian Ewins (http://www.jguru.com/guru/viewbio.jsp?EID=301660)
Question originally posed by John Zukowski PREMIUM
(http://www.jguru.com/guru/viewbio.jsp?EID=7
It's an emerging standard for describing hypertext links in XML. Its not limited to the
one-way links you have in HTML - you can have bidirectional links, annotations, you
can link to any location in a document (using XPointers), and so on. The official
homepage is at W3C and you can find an introduction here.
Is there a Java API which can generate an XPath String from the source
node to the destination node?
For example:
<-- <section>
<titre nom="titre1">
<para>bla</para>
<para>pou</para>
</titre>
</section>-->
source node : titre;
destination node : the second para;
Are there tools which can convert Microsoft Word documents into XML?
Location: http://www.jguru.com/faq/view.jsp?EID=302121
Created: Jan 14, 2001 Modified: 2001-01-14 19:57:15.499
Author: Brian Ewins (http://www.jguru.com/guru/viewbio.jsp?EID=301660)
Question originally posed by mehdi lababidi
(http://www.jguru.com/guru/viewbio.jsp?EID=48184
Free MS tool
Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7), May 15,
2001
Microsoft has a tool to help you Export a Word Document to XML.
OK, but I can't get the sample set up. Xalan runs ...
Author: Ion Freeman (http://www.jguru.com/guru/viewbio.jsp?EID=331356), Feb 16,
2001
OK, but I can't get the sample set up. Xalan runs great, and do Tomcat's servlet
samples, but I'm needing some help in editing the server.xml and web.xml files, or
even knowing which web.xml file to edit. Should I create a WEB-INF folder? Does it
need a classes subfolder? I'm using the Tomcat ISAPI dll on W2K/IIS5. Tomcat's in
c:\inetpub\tomcat, Xalan's in c:\inetpub\xalan. ion
How can I generate and store an XML file by writing a PL/SQL procedure?
Location: http://www.jguru.com/faq/view.jsp?EID=302129
Created: Jan 14, 2001 Modified: 2001-01-15 19:32:54.367
Author: Brian Ewins (http://www.jguru.com/guru/viewbio.jsp?EID=301660)
Question originally posed by Srini Vasan
(http://www.jguru.com/guru/viewbio.jsp?EID=284085
You can't. What happens when the BLOB just contains a filename? Your DTD isn't too
smart. You should think of doing one of:
If this really is a BLOB (and not a CLOB) then the data will - hopefully - only be
included in a CDATA element anyway. The DOM allows you to distinguish between
CDATA and other text nodes.
foo='<xsl:value-of select="/xpath/for/foovalue"/>'
</script>
in your XSL.
How can I read a paramater passed in a URL to an XML file? For example,
can I get the value of cat1 in
http://www.brainbench.com/xml/bb/common/testcenter/subcat.xml?cat1
=2
Location: http://www.jguru.com/faq/view.jsp?EID=302137
Created: Jan 14, 2001 Modified: 2001-01-15 19:42:57.927
Author: Brian Ewins (http://www.jguru.com/guru/viewbio.jsp?EID=301660)
Question originally posed by Anshul Agarwal
(http://www.jguru.com/guru/viewbio.jsp?EID=98160
XML isn't a language you execute. So something else is processing your XML, right?
Its that something else that can provide you with the values in a number of ways.
One way (if you are generating dynamic XML) is to provide the request as XML
elements. Another way is to pass the parameters to the XSL processor, which can
make them available via extension functions. See here for examples of using Apache
Xalan with extensions.
Comments and alternative answers
Is it VoxML or VoiceXML?
Location: http://www.jguru.com/faq/view.jsp?EID=305408
Created: Jan 17, 2001 Modified: 2001-01-19 07:25:11.003
Author: Kenneth Liu (http://www.jguru.com/guru/viewbio.jsp?EID=304008)
Question originally posed by John Zukowski PREMIUM
(http://www.jguru.com/guru/viewbio.jsp?EID=7
It's both. VoiceXML and VoxML are both standards which are used for creating
speech and voice enabled web applications. VoxML was first developed by Motorola in
1998. Later, they were joined by Lucent, AT&T, and IBM to form the VoiceXML Forum
in order to continue the work. VoiceXML 1.0 was accepted by the W3C in May 2000.
Supposedly some of the original authors of the VoxML standard left Motorola to head
up voice application development efforts in the other companies, and so the
VoiceXML Forum was formed.
They are probably using XSLT to transform XML files to HTML format. XSLT is
commonly used to transform XML files which are purely data and content to HTML
files which include both content and presentation information. See the Apache XML
Cocoon project for a good example of this.
VoiceXML is used to create voice enabled applications for use with any regular phone.
These applications often take the form of phone trees ("press 1 to do this, press 2 to
do that") but can use ASR (automated speech recognition) to recognize spoken
responses in addition to the normal touch tones. VoiceXML can also be used to do
TTS (text to speech) instead of using prerecorded content. VoiceXML documents
require an interpreter which normally runs on a powerful server.
VoiceXML and WAP are often mentioned in the same context because they are both
seen as ways of accessing the Web using a wireless device. With WAP, the screen is
used to display the content; with VoiceXML, TTS is used to play the content aloud.
It depends on what kind of application you are talking about. VoiceXML is really
designed for web applications. It's another markup language - instead of displaying
content on a screen, it uses speech and voice response to interact with the user
(usually) over a phone. If you are writing a desktop application, then VoiceXML
probably won't be suitable. If you want to embed voice commands to control your
app, then JavaSpeech is probably the way to go.
Is there any transformation tool that can convert the XML of one format to
XML of another format?
Location: http://www.jguru.com/faq/view.jsp?EID=311010
Created: Jan 24, 2001 Modified: 2001-01-24 11:27:51.55
Author: Davanum Srinivas (http://www.jguru.com/guru/viewbio.jsp?EID=2011)
Question originally posed by krithi vasan
(http://www.jguru.com/guru/viewbio.jsp?EID=32927
"XSLT is a language for transforming XML documents into other XML documents."
"XSLT is designed for use as part of XSL, which is a stylesheet language for XML. In addition to
XSLT, XSL includes an XML vocabulary for specifying formatting. XSL specifies the styling of an
XML document by using XSLT to describe how the document is transformed into another XML
document that uses the formatting vocabulary."
"XSLT is also designed to be used independently of XSL. However, XSLT is not intended as a
completely general-purpose XML transformation language. Rather it is designed primarily for the
kinds of transformation that are needed when XSLT is used as part of XSL."
There are various XSLT engines that can perform these transformations. See the
comprehensive list at:
http://www.xslt.com/xslt_tools_engines.htm
Comments and alternative answers
How can I embed Java code in XSL? I want to call a Java object from my
XSL file. This object will return HTML code. This HTML code will then become
part of my XSL before it goes through XSLT. Is this possible or am I asking
for too much?
Location: http://www.jguru.com/faq/view.jsp?EID=311022
Created: Jan 24, 2001 Modified: 2001-01-24 11:24:28.481
Author: Davanum Srinivas (http://www.jguru.com/guru/viewbio.jsp?EID=2011)
Question originally posed by shiva vithal
(http://www.jguru.com/guru/viewbio.jsp?EID=55743
Yes, it can be done. But is heavily dependent on the XSLT Engine. For example in
Xalan (open source XSLT Engine from Apache) you can use Java or JavaScript in your
XSL's.
http://xml.apache.org/xalan/extensions.html
I am retreiving XML resources from the net and transforming them locally
via XSL with Apache Xalan. Whenever an XML file contains a DOCTYPE
declaration, the parser insists on looking up the remote DOCTYPE URL. How
can I avoid that?
Location: http://www.jguru.com/faq/view.jsp?EID=311028
Created: Jan 24, 2001 Modified: 2001-01-24 11:22:55.72
Author: Davanum Srinivas (http://www.jguru.com/guru/viewbio.jsp?EID=2011)
Question originally posed by Christian Sell
(http://www.jguru.com/guru/viewbio.jsp?EID=219526
The example code which I have working reads XML from a File using:
If you have built a schema with the name say as contact.xsd and with a root
element of contactdb then inside the xml file you need to
<contactdb xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="contact.xsd">
or if it is a relative URL
<xmlns:xsi ="http://www.w3.org/1999/XMLSchema/instance"
xsi:schemaLocation= "http://www.xmls.com/contact/contact.xsd">
where the url is the relative path or the document root of a web server.The schema
processor should also be in the classpath of your JVM/servlet engine etc.
hi Shuchi,
I was desparately going thru resources to solve my prob and happened to find u. I am
facing probs in validating xml document against schema.
I got xml file and schema (which is tested against couple of schema validators)..but
having difficulties in implementing it.
XMLFILE:
SCHEMA:
CODE SAMPLE:
xmlFilePath= "F:\\Raptor\\Development\\xml\\SupplierInvoice.xml";
parser.setDocumentHandler(handler);
parser.setErrorHandler(handler);
try {
parser.setFeature("http://apache.org/xml/features/validation/schema",true);
parser.setFeature("http://apache.org/xml/features/validation/schema-full-
checking",true);
parser.parse(xmlFilePath);
the basic prob is not with validating but program doesnt pick up my .xsd file at all. if
u have any clue, plz give me feedback at the earliest possible as this checked my
progress with the project.
thanx in advance,
srinivas
How does one install the jdom-b5 winzip file from www.jdom.org?
Location: http://www.jguru.com/faq/view.jsp?EID=314605
Created: Jan 28, 2001 Modified: 2001-01-29 18:01:58.926
Author: Chandra Patni (http://www.jguru.com/guru/viewbio.jsp?EID=33585)
Question originally posed by jarsha vardhan avvari
(http://www.jguru.com/guru/viewbio.jsp?EID=312987
If you are running JDK1.2 or higher versions, you can simply unzip the zip file and
copy the jdom.jar into your JAVA_HOME/jre/lib/ext dir. If you are using JDK1.1 then
you need to copy 1.1 version of jar file and collections.jar file to
JAVA_HOME/jre/lib/ext dir. Also you need to have xerces parser file into your
classpath. You can simply also copy the jar xerces jar file(s) in
JAVA_HOME/jre/lib/ext dir. If you don't have access to ext dir then simply include
these jar files into your classpath.
I've got two files, an XML and XSL file. The XML file contains my data and
the XSL file contains the layout of the HTML. How do I transform these files
to produce the HTML (as specified in my XSL). I did these in MS
environment using .asp so I'll like to know how to do the same in Java
either using .jsp or servlet or anything.
Location: http://www.jguru.com/faq/view.jsp?EID=314892
Created: Jan 29, 2001 Modified: 2001-01-29 18:00:08.398
Author: KIRAN KUMAR (http://www.jguru.com/guru/viewbio.jsp?EID=314877)
Question originally posed by Jukha Maseko
(http://www.jguru.com/guru/viewbio.jsp?EID=311955
For converting the XML to HTML using XSL, you can make use of the Xalan XSLT
engine.
Comments and alternative answers
Re: You can make use of the following example for your...
Author: Foo Shi Hao (http://www.jguru.com/guru/viewbio.jsp?EID=436481), Jul
23, 2001
Hi, your code is to display the XML data formatted by XSL right? And Xalan is
used to parse them? I tried out the exact code, changing the XML and XSL to my
own filenames. But there are errors... I just recently installed Xalan-Java 2. And i
use tomcat 3.2.2 Can you help? <<Autoexec.bat>> SET
CATALINA_HOME=C:\jakarta-tomcat-3.2.2 SET JAVA_HOME=C:\jdk1.3.1
SET PATH=C:\PROGRA~1\ULTRAE~1;c:\jdk1.3.1\bin;%PATH% SET
CLASSPATH=C:\jdk1.3.1\lib;c:\xalan-j_2_1_0\bin;C:\jdk1.3.1\jre\lib\ext
<<Errors occurred>> Error: 500 Internal Servlet Error:
javax.servlet.ServletException: SAX Exception Root cause:
javax.xml.transform.TransformerException: SAX Exception
Re: Re: You can make use of the following example for your...
Author: Kumar Sachwani
(http://www.jguru.com/guru/viewbio.jsp?EID=523774), Oct 18, 2001
HI
If you have found the correct solution then please please please tell me
i am facing similar problem
Bye
Kumar
Re: Re: Re: You can make use of the following example for your...
Author: Kumar Sachwani
(http://www.jguru.com/guru/viewbio.jsp?EID=523774), Oct 18, 2001
hi all
i finally found the solution
problem is in Tomcat version 3.2.1 and 3.2.2 the problem is with jaxp.jar
edit tomcat.bat and change the classpath settings to
set CLASSPATH=%CP%;%CLASSPATH%
to
set CLASSPATH=%CLASSPATH%;%CP%
now run the tomcat.bat file again ans start tomcat
How can I embed a space in text in an XSL? Using "& nbsp;" treats it as an
entity.
Location: http://www.jguru.com/faq/view.jsp?EID=315231
Created: Jan 29, 2001 Modified: 2001-01-29 17:52:38.424
Author: Renato Michielin (http://www.jguru.com/guru/viewbio.jsp?EID=255654)
Question originally posed by Shiv Dutt
(http://www.jguru.com/guru/viewbio.jsp?EID=286598
Tell the XSLT processor not escape the symbol &. Put the escape sequence for the
symbol, "& amp;", in a xsl:text element, and set the disable-output-escaping
attribute to yes.
<xsl:text disable-output-escaping="yes">
& amp;nbsp;</xsl:text>
Comments and alternative answers
If you want some white space in the output tree, e...
Author: Thomas BROYER (http://www.jguru.com/guru/viewbio.jsp?EID=319084),
Feb 2, 2001
If you want some white space in the output tree, enclose it in an xsl:text element or
some element with xml:space="preserve".
<xsl:text> </xsl:text>
References
XSLT Recommendation, especially the Whitespace stripping section
java.lang.NoSuchMethodError
at org.jdom.input.DOMBuilder.buildTree(DOMBuilder.java:416)
We are almost sure that this could be a configuration problem. What do you
think about?
Location: http://www.jguru.com/faq/view.jsp?EID=315879
Created: Jan 30, 2001 Modified: 2001-02-01 05:57:29.931
Author: Chandra Patni (http://www.jguru.com/guru/viewbio.jsp?EID=33585)
Question originally posed by Isaac Lopez
(http://www.jguru.com/guru/viewbio.jsp?EID=266468
This error is encountered because of incompatiable version of XML jar files. You
might have some other XML jar file (say xml.jar shipped with tomcat) either in your
classpath or in JAVA_HOME/jre/lib/ext dir when you are running your application in
Solaris.
You need to make sure that you don't have some old version of XML jar files in your
classpath or in ext dir. Replace such files by xerces.jar file and you should not get
this error. Note that the jar files which are dropped into ext dir are searched before
the jar files in classpath.
Also please refer to similar problem while installing cocoon in tomcat setup.
RELAX stands for REgular LAnguage description for XML. It can be thought of as a
namspace aware DTD written in xml syntax. RELAX also borrows datatypes from XML
Schema Part 2. For more info, please refer to RELAX Tutorial and FAQ
How can I use XML in EJB for data storage and management?
Location: http://www.jguru.com/faq/view.jsp?EID=317835
Created: Feb 1, 2001 Modified: 2001-02-01 05:49:44.515
Author: KIRAN KUMAR (http://www.jguru.com/guru/viewbio.jsp?EID=314877)
Question originally posed by Risheng Lin
(http://www.jguru.com/guru/viewbio.jsp?EID=46809
Using an XML repository like "TAMINO" you can store all your XML files and query
them through your EJBs.
How can I embed XML code in my JSP? Where can I give a link to my XSL
file?
Location: http://www.jguru.com/faq/view.jsp?EID=318016
Created: Feb 1, 2001 Modified: 2001-02-01 18:00:40.771
Author: Renato Michielin (http://www.jguru.com/guru/viewbio.jsp?EID=255654)
Question originally posed by Gopi chand
(http://www.jguru.com/guru/viewbio.jsp?EID=259984
.........xml............
(Put the page directive on the second line, otherwise the compiler leaves a blank
first-line and this may cause an error when XML document is parsed).
You may link to an XSL style sheet from the page inserting an xml-stylesheet
processing-instruction after the xml declaration:
<?xml version="1.0" ?>
.........xml............
To code XML dynamically, add a bean to the page and call a method to populate an
element:
<jsp:useBean id="mybean" class="mypackage.myclass" />
You can make use of commercially available repositories like tamino and bladerunner.
You can deploy all your XML files to that and make searches in the repository.
Comments and alternative answers
Look at XSet
Author: Ramkumar Natarajan (http://www.jguru.com/guru/viewbio.jsp?EID=52141),
May 28, 2001
http://www.cs.berkeley.edu/~ravenben/xset/ XSet is a fast in-memory (backed up on
disk) database for storing and querying XML documents which supports limited
ACID semantics. I've used it and found it to be extremely fast and very usable.
XPath
The XPath language allows you to retrieve nodes from an XML tree. It can be seen as
the SQL for XML. (It has in fact many limitations which prevent such an analogy and
have lead the creation of XML Query).
XPointer
XPointer allows retrieving of data from other documents. Its goal is to be used in URI
fragment identifiers.
It extends XPath with the selection of regions (ranges) or points (whereas XPath only
selects nodes).
In brief :
• XPath isn't self-sufficient. Some application has to provide an evaluation
context.
• XPointer makes use of and extends XPath while providing an evaluation
context.
Currently only Mozilla, Amaya and MSIE6 have XLink support (and only for simple
links).
Many possibilities:
XML:
<?xml version="1.0"?>
<Numbers>
<Number>
<Digit>1</Digit>
<Name>One</Name>
<Other>First</Other>
</Number>
</Numbers>
Desired output:
<Number>
<Digit>1</Digit>
<Name>One</Name>
<Other>First</Other>
</Number>
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version ="1.0">
<xsl:output method="xml"/>
<xsl:template match="/Numbers">
<xsl:value-of select="Number" disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
Location: http://www.jguru.com/faq/view.jsp?EID=319171
Created: Feb 2, 2001 Modified: 2001-02-12 07:27:47.49
Author: Thomas BROYER (http://www.jguru.com/guru/viewbio.jsp?EID=319084)
Question originally posed by Stefan Lecho
(http://www.jguru.com/guru/viewbio.jsp?EID=32509
What you need is xsl:copy-of.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/Numbers">
<xsl:copy-of select="Number[1]">
</xsl:template>
</xsl:stylesheet>
I am using Xalan 1.2.1 and Sun JDK 1.2.2_06. I am trying to use an XSL
stylesheet to transform one XML document into an external XML API
request. I am trying to dynamically generate the DocType element so that it
builds the system URL using an element contained in the document I am
transforming. How do I do this? I tried:
<xsl:output doctype-
system="http://{/KPRequest/AppURL}/xmldocs/xmldtd/CommonRequest.dtd"
doctype-public="-//KP2000//DTD - KP Common IDL API XML Request//EN"/>
and this:
<xsl:output doctype-
system="http://{/KPRequest/AppURL[text()]}/xmldocs/xmldtd/CommonRequest
.dtd" doctype-public="-//KP2000//DTD - KP Common IDL API XML
Request//EN"/>
And in both cases, the Xalan XSL processor did not alter the attempts to
reference the AppURL element at all. It just output the select and the curly-
braces right into the DOCTYPE element. Is there any way to do this? Is this
limitation in a spec somewhere that I haven't read?
Location: http://www.jguru.com/faq/view.jsp?EID=319173
Created: Feb 2, 2001 Modified: 2001-02-12 07:44:51.857
Author: Thomas BROYER (http://www.jguru.com/guru/viewbio.jsp?EID=319084)
Question originally posed by Jonathan Morgan
(http://www.jguru.com/guru/viewbio.jsp?EID=281937
This is a limitation of XSLT1.0. Top-level elements cannot have attribute-value-
templates. XSLT1.1 will allow AVTs in xsl:output. With XSLT1.0, you have to modify
the output tree after the transformation is done.
<?xml version="1.0"?>
<doc>
<data>
<person>
<name>John Smith</name>
<age>26</age>
<phone>(416)123-2345</phone>
<city>Toronto</city>
</person>
<person>
<name>Mary Lynn</name>
<age>16</age>
<phone>(416)133-2333</phone>
<city>New York</city>
</person>
<person>
<name>Don John</name>
<age>16</age>
<phone>(456)143-2225</phone>
<city>San Francisco</city>
</person>
<data>
<format>
<field>age</field>
<field>name</field>
</format>
</doc>
How can I write a stylesheet which will output the information from the
<data> section according to the format (i.e. field selection and order)
specified in <format> section, i.e. for the example above the output would
be:
26
John Smith
16
Mary Lynn
16
Don John
What I was trying to do is to run through the <data> section with xsl:for-
each and for each <person> entry run through the <format> section
selecting the elements from <person> with the names specified in
<format> section, i.e.:
<xsl:for-each select="/doc/data/person">
<xsl:for-each select="/doc/data/format/field">
It appears that the API won't let you just add a DocumentType node? Any ideas or
work arounds for this?
thanks, John
Most XML parsers support validation. In Apache Xerces, for example, the property for
validation is set to true by default. Every XML file which contains a "doctype"
reference to a DTD gets validated.
Comments and alternative answers
1. The data is static, and is not being concurrently updated by other applications.
2. You would replicate (or make it accessible) for all instances in case of clustering.
I presume that this is the case, and so, storing it outside a database makes your
application more flexible.
On the otherhand, if this data is shared (read and written) across multiple
applications, and therefore is subjected to transactions, you should consider a
database.
How to convert a DOM Document object into an XML file using JAXP?
Location: http://www.jguru.com/faq/view.jsp?EID=320363
Created: Feb 4, 2001 Modified: 2001-02-12 07:39:43.438
Author: Chandra Patni (http://www.jguru.com/guru/viewbio.jsp?EID=33585)
Question originally posed by Tarun Chopra
(http://www.jguru.com/guru/viewbio.jsp?EID=315456
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
.......
...
rog
TransformerFactory tf = TransformerFactory.newInstance();
transformer.setOutputProperty( "{http://xml.apache.org/xslt}indent-amount",
"4" );
transformer.transform(domSource, streamResult);
COnverting DOM Document Object into XML file removes the DTD
Author: Ashit Shetty (http://www.jguru.com/guru/viewbio.jsp?EID=749998), Feb 6,
2002
I have a wellformed XML with a DTD written in it . I am parsing this XML and
manipulating some information in it and by using the
javax.xml.transform.Transformer class , trying to write to another XML file. The
problem is even though the XML is written properly my original DTD is lost(not seen
in the new XML file) . Is there anyway of retaining the DTD ?
How can I pass XML data from one web server to another web server and
get the reponse back from it?
Location: http://www.jguru.com/faq/view.jsp?EID=329362
Created: Feb 14, 2001 Modified: 2001-02-28 10:55:51.484
Author: Ravi Van (http://www.jguru.com/guru/viewbio.jsp?EID=329336) Question
originally posed by Madhu Menon
(http://www.jguru.com/guru/viewbio.jsp?EID=29982
Sure you can! Each of the web servers should be capable of understanding and
processing XML and in turn generating XML.
You can achieve this as follows: Set the mime-type in your webserver configuration
file so that the request is routed to the appropriate application. From then on, it is
the responsibility of that application to understand/consume/generate XML.
How can I import nodes recursively from one document object to another
using Java's J.A.X.P ?
Location: http://www.jguru.com/faq/view.jsp?EID=330284
Created: Feb 15, 2001 Modified: 2001-02-16 07:35:38.554
Author: Brian Ewins (http://www.jguru.com/guru/viewbio.jsp?EID=301660)
Question originally posed by navin bhaskar
(http://www.jguru.com/guru/viewbio.jsp?EID=83923
You can't. JAXP is an API for getting hold of a document object or a parser. Beyond
that, you're into the DOM, SAX or JDOM APIs instead. The easiest approach is to use
JDOM, which has FAQ examples on how to reparent an element recursively. JDOM
does not have a Node abstraction. Neither does JAXP for that matter, its part of DOM.
If you are committed to using the DOM you need a DOM Level-2 capable parser. You
need to look up the documentation for importNode() . If it's 'deep' parameter is true
it will import recursively.
Comments and alternative answers
Re: Using JAXP for importing nodes from one document to another
Author: João Montenegro (http://www.jguru.com/guru/viewbio.jsp?EID=794596),
May 15, 2002
What about Document.importNode() method?
João
Sun have had SAX and DOM APIs for XML Parsing for some time. Now, there
are a number of new standards, namely JAXM and JAXP, for XML messaging
and parsing respectively. What exactly do these new interface standards
achieve, and where do they fit with the APIs that Sun has already?
Location: http://www.jguru.com/faq/view.jsp?EID=330288
Created: Feb 15, 2001 Modified: 2001-02-16 07:39:42.271
Author: Brian Ewins (http://www.jguru.com/guru/viewbio.jsp?EID=301660)
Question originally posed by james murphy
(http://www.jguru.com/guru/viewbio.jsp?EID=278791
Sun never had SAX and DOM. They are xml.org and W3C parser specs, respectively.
JAXP is a layer above these which allows parsers to become 'pluggable'. SAX and
DOM left a couple of issues open which led to vendor-specific extensions, e.g. to get
the parser in the first place. If you work with JAXP you can switch parser without
changing your code, just replace the parser JAR. JAXM is not a standard yet, its a
working draft of the 'M Project'. It will standardise later when ebXML solidifies later
this year, and is meant to provide an API for reliable XML messaging for business
transactions. This is a different layer of abstraction from JAXP, SAX, and DOM (level
1), which are all about parsing. JAXM fits in with JAXP in the same way that your own
application would: you can switch parsers and JAXM will still work, because it uses
JAXP.
When should XML be used? I know how to create an XML file, a DTD and
parse data from an XML page. But I am still unable to find the right
application of XML in out site (an insurance company). We have Oracle 8i as
our database and use JSPs and EJBs 1.0. We have a set of questions asked
and based on that we quote a premium. We also have searches done on
data.
Location: http://www.jguru.com/faq/view.jsp?EID=330704
Created: Feb 15, 2001 Modified: 2001-02-16 07:38:17.769
Author: David Smith (http://www.jguru.com/guru/viewbio.jsp?EID=105814)
Question originally posed by Ashwin Chathuruthy
(http://www.jguru.com/guru/viewbio.jsp?EID=83111
Sometimes a tool just isn't appropriate. Just because you know how to do something
doesn't mean that you should.
Generating web pages from applications - the application can output XML and pass it
through an XSL stylesheet to add all the pretty HTML eye-candy.
There are lots of other good uses for XML, I'm sure. Rather than looking for uses for
the new tool you've learned, you should be looking for solutions to the problems you
have.
How does one store text from multiple natural languages, such as Japanese
and Chinese, in one XML file which has 'English' as the main language?
Location: http://www.jguru.com/faq/view.jsp?EID=330724
Created: Feb 15, 2001 Modified: 2001-02-16 07:37:10.584
Author: David Smith (http://www.jguru.com/guru/viewbio.jsp?EID=105814)
Question originally posed by rajesh vachepally
(http://www.jguru.com/guru/viewbio.jsp?EID=50666
XML's "natural" encoding is Unicode UTF-8. This means that you can mix characters
from different languages freely within an XML document. You will, however, need a
UTF-8 editor.
In a project I'm currently working on we mix English and Japanese text in the same
documents with English sections enclosed within <english> </english> tags and
Japanese within <japanese> </japanese> tags. The only reason we tag the
languages is so that we can choose which to display - it does not make any
difference to the XML parser. It is perfectly valid to mix any characters together while
using Unicode
It is also possible to encode XML documents using a character set other than UTF-8.
In Japan there are pre-existing character sets such as EUC and JIS which are in
common use. These character sets also encompass ASCII so it is easy to mix English
and Japanese, however if we needed a third language we could not do it within a
single document since XML only allows one encoding for the entire document. For
that reason, it's best to convert to Unicode as soon as you can. Using Java and
Xerces it is fairly easy to convert character sets into/out of Unicode.
This question does indicate that the author of this question considers a XML
document as a runtime entity.
For example, you can define the properties for a database connection and the query in
a XML file, and this XML file is passed as parameter to a jsp or asp that executes the
query, showing you the results in html.
Every XML parser I've seen comes with the "standard" packages (such as
org.w3c.dom, org.xml.sax, javax.xml.parsers etc). The unusual and weird
thing is that each parser I've seen comes with a *different* version of those
packages.
I've checked out Xerces 1.3.0, JAXP 1.01 and IBM XML4J which comes with
VAJ 3.5.
How come there are many versions of a package? Where can I get the latest
versions of those packages?
Location: http://www.jguru.com/faq/view.jsp?EID=331808
Created: Feb 16, 2001 Modified: 2001-02-17 07:44:44.61
Author: Subrahmanyam Allamaraju
(http://www.jguru.com/guru/viewbio.jsp?EID=265492) Question originally posed by
Isaac Shabtay (http://www.jguru.com/guru/viewbio.jsp?EID=325037
This is because there are two sets of DOM and SAX APIs around - SAX 1 and SAX 2,
and DOM Level 1 and Level 2.
• Xerces 1.3 supports SAX 2 and DOM Level 2. So, you'll find those versions of
SAX and DOM APIs.
• JAXP 1.01 supports SAX 1 and DOM Level 1. So, you'll find the older versions
of SAX and DOM APIs.
• I'm not sure of what is includes in VAJ3.5. But it could be one of the above
two.
DOM
SAX
JAXP
You cannot have more than one DOCTYPE declaration in an XML document, but one
document can "call" several DTD's using external parameter entities.
Example:
Let's say you have some document with a «svg:svg» root element and its associated
DTD, and another document with a «mml:math» root element and its associated
DTD.
Now you want to have a single document with, say, a «bar» root element with
allowed children any of «svg:svg» or «mml:math» and their subtrees as declared in
the two DTD's mentionned above.
I wrote a servlet. It is sending XML data as response object. The XML file is
displayed fine. But now I want to add a style sheet to this XML file. For that
I copy the XSL file to public_html directory and in servlet I added this file to
the response object. Now whenever I request for this servlet the brower
produces an error
"This page is accessing information that is not under its control. This poses
a security risk. Do you what to continue?".
If I agree, it works fine. But I don't what that message before displaying.
How to eliminate that?
Location: http://www.jguru.com/faq/view.jsp?EID=332552
Created: Feb 18, 2001 Modified: 2001-02-20 20:28:03.884
Author: Arun Bharathan (http://www.jguru.com/guru/viewbio.jsp?EID=106958)
Question originally posed by Rama Arja
(http://www.jguru.com/guru/viewbio.jsp?EID=318080
It seems that you are trying to access your XSL through HTTP where as the request
for the XML was generated in HTTPS and a warning as such is generated by the
browser.
There are two ways to solve this. Move your XSL into a secure area. (ie, XSL should
be served through secure layer) Or do the transforms using a XSLT (like xalan) on
the server side itself and serve the generated page. (This works in all browsers and
does not depend on XML aware browsers.)
Comments and alternative answers
error : "This page is accessing information that is not under its control. This
poses a security risk. Do you what to continue?"
Author: Kevin McCoy (http://www.jguru.com/guru/viewbio.jsp?EID=797510), Mar
14, 2002
Actually, this message is caused by an Internet Explorer option, not HTTP/HTTPS.
Last time I saw it (a "yes" answer produced desired results) the suspected cause was
the Security / Miscellaneous / Access data across domains setting (I haven't yet
verified that this was the setting).
Re: error : "This page is accessing information that is not under its control.
This poses a security risk. Do you what to continue?"
Author: Carlos Camacho (http://www.jguru.com/guru/viewbio.jsp?EID=824608),
Apr 4, 2002
It seems Kevin is right. I was receiving this message constantly and now it's gone,
after I changed the Security / Miscellaneous / Access data across domains setting
to "enable" instead of "prompt".
Thanks.
Re: error : "This page is accessing information that is not under its control.
This poses a security risk. Do you what to continue?"
Author: Hans Hillewaert (http://www.jguru.com/guru/viewbio.jsp?EID=892348),
May 25, 2002
Thanks a lot for you suggestion. This really did the trick. I've been bothered with
that annoying popup for weeks, and now it's finally gone.
Great!!
How can I validate an XML file against a DTD without including the DTD file
in the XML file?
Location: http://www.jguru.com/faq/view.jsp?EID=332561
Created: Feb 18, 2001 Modified: 2001-02-20 20:13:18.488
Author: Arun Bharathan (http://www.jguru.com/guru/viewbio.jsp?EID=106958)
Question originally posed by Rama Arja
(http://www.jguru.com/guru/viewbio.jsp?EID=318080
As per the XML1.0 specification the DTD could be declared inside the XML, or
externally as a seperate URI or combination of both.
I think the better way to do that is to use an XSLT processor that lets you to
transform an XML document to any format included html, pdf, or of course simple
text. I suggest you to learn more about XSL/XSLT.
Where can I get information and sample code for using JAXP and JAXM?
Location: http://www.jguru.com/faq/view.jsp?EID=332919
Created: Feb 19, 2001 Modified: 2001-02-20 20:25:06.495
Author: Luigi Viggiano (http://www.jguru.com/guru/viewbio.jsp?EID=101985)
Question originally posed by Rajesh Sawant
(http://www.jguru.com/guru/viewbio.jsp?EID=331010
</xsl:stylesheet>
Can we make a generalised schema file by which we can validate only the
hierarchy of the target XML file, not the tag names in that XML file?
Location: http://www.jguru.com/faq/view.jsp?EID=339807
Created: Feb 27, 2001 Modified: 2001-02-27 08:22:33.98
Author: Luigi Viggiano (http://www.jguru.com/guru/viewbio.jsp?EID=101985)
Question originally posed by Sankar Gandhi
(http://www.jguru.com/guru/viewbio.jsp?EID=141972
Speaking about hierarchy it means that you have defined father elements and child
elements. How's possible to check hierarchy without checking tag names? Hierarchy
implies tag name checking.
If you don't specify any DTD or XMLSchema the only check done is about the well
formedness of the XML. In some way, this can be assimilated to a basic hierarchy
check.
With this you don't serialize the DOM Object but you transform everything to an XML
String (easier to serialize, and obviously faster to transmit). The disadvance is that,
from the other side you get a String to be parsed to a Node. Anyway you can try to
check performance improvements/loss. (I think should be an improvement.)
This should be because some jar's class is missing; add all the needed jars
(xerces.jar for example) to the classpath of the servlet-engine.
Check the SAX version and all xml jars too. Maybe your servlet engine is using an
older one (maybe because the order of the jars in the classpath is wrong).
Try to open the jar of the servlet engine and check if it contains SAX classes. If yes,
put the jar containing your (updated) sax classes before the jar of the servlet engine
on its startup command. Note that inside xerces.jar, sax classes are included. So...
try to put xerces.jar before the servlet engine's jars.
If the problems persists, try to put xerces as the first jar in the classpath.
Example
before
java -cp servletEngine.jar;...;xerces.jar;... servletEngine.Server
after...
java -cp xerces.jar;servletEngine.jar;... servletEngine.Server
Can I use a Generic SAX/DOM XML parser for Tomcat instead of parser.jar?
I tried using Xerces and get class not found errors for sun.xxxx parser
during Tomcat initialization.
Location: http://www.jguru.com/faq/view.jsp?EID=341619
Created: Mar 1, 2001 Modified: 2001-03-01 07:25:10.775
Author: Luigi Viggiano (http://www.jguru.com/guru/viewbio.jsp?EID=101985)
Question originally posed by bruce carson
(http://www.jguru.com/guru/viewbio.jsp?EID=217941
System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
"org.apache.xerces.jaxp.DocumentBuilderFacto
ryImpl");
System.setProperty("javax.xml.parsers.SAXParserFactory",
"org.apache.xerces.jaxp.SAXParserFactoryImpl
");
Comments and alternative answers
I haven't been able to run the SimpleTransform example included with JAXP 1.1 as a
JSP under Tomcat 3.2.1
Then I saw this entry and defined both system properties (as well as
javax.xml.transform.TransformerFactory, just in case).
I know I have access to the classes, because I tried a Class.forName and got no
ClassNotFoundException
table ELEMENT
ELEM-ID number(9) primary key,
ELEM-NAME char(30),
ELEM-CONTENTS char(30),
PARENT-ID number(9), (references another ELEM-ID)
table ATTRIBUTE
ATTR-ID number(9) primary key,
ATTR-NAME char(30),
ATTR-VALUE char(30),
ELEM-OWNER-ID number(9), (refrences an ELEM-ID)
Elements with null in PARENT-ID are root's elements, so you can make a query
selecting null in PARENT-ID to get the list of root's elements.
To get all the children of an element you have to select all elements having parent-id
= your elem-id.
Where can I find source code examples or tutorials relating to JAXP 1.1?
Location: http://www.jguru.com/faq/view.jsp?EID=347493
Created: Mar 8, 2001 Modified: 2001-03-09 07:08:11.356
Author: Chandra Patni (http://www.jguru.com/guru/viewbio.jsp?EID=33585)
Question originally posed by Tracey Doyle
(http://www.jguru.com/guru/viewbio.jsp?EID=347176
JAXP revisited at IBM developerWorks gives an introduction to JAXP 1.1 features and
usage code snippets. Also, section 3 of JAXP 1.1 Specification Review contains some
examples of JAXP1.1 features.
I'm looking for a DOM-style XML parser that doesn't load the entire
document. Rather, it would let you get an element, then iterate over the
element's children, presenting each child as a DOM node but only loading
one child at a time (to conserve memory when there's a large number of
children. Where I can get such a parser?
Location: http://www.jguru.com/faq/view.jsp?EID=347543
Created: Mar 8, 2001 Modified: 2001-03-09 07:07:43.7
Author: Chandra Patni (http://www.jguru.com/guru/viewbio.jsp?EID=33585)
Question originally posed by Bobby Woolf
(http://www.jguru.com/guru/viewbio.jsp?EID=346655
You can use JDOM API (See also JSR0102) to achieve this effect. The following
snippet of code shows how JDOM can be used to get the java.util.List of
child(ren) of a node. In JDOM, a node is said to be org.jdom.Element.
org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder();
org.jdom.Element root = builder.build(new
java.io.File("file.xml")).getRootElement();
java.util.List children = root.getChildren();
//...
An org.jdom.Element can be convert to org.w3c.dom.Element by using
org.jdom.output.DOMOutputter class. Moreover, JDOM lets you change the modify
the document without having to worry about underlying parser. See also: Parsing a
very large XML file FAQ.
Comments and alternative answers
Selective loading
Author: Subrahmanyam Allamaraju
(http://www.jguru.com/guru/viewbio.jsp?EID=265492), Jun 3, 2001
I original answer to the question is incorrect and is misleading.
There were a few attempts ("pull-style" parsers) to solve the problem of selectively
loading contents of XML into memory. Refer to
http://www.ltg.ed.ac.uk/software/xml/ for one such attempts. However there are no
standard efforts to build parsers meeting this requirement.
After setting a variable using the <xsl:variable> tag, how can I change the
value of that variable somewhere else in the xsl document?
Location: http://www.jguru.com/faq/view.jsp?EID=348065
Created: Mar 9, 2001 Modified: 2001-03-12 06:57:33.276
Author: JP Moresmau (http://www.jguru.com/guru/viewbio.jsp?EID=127279)
Question originally posed by Aseel Ali
(http://www.jguru.com/guru/viewbio.jsp?EID=339840
You can't. Once set, a variable is constant in XSLT. You'll need to create a new
variable.
Question : Can XSL XSLT be used with SAX? This is what we want to do: We
have live tick data stream, (an XML data stream). So we cannot use DOM.
The SAX' limitation is because with SAX there's no concept of hierarchy, and this is a
requirement for XSL processing.
Xalan can use a SAX source, but no transformation is done until the document
is complete. The parser will throw an exception if more than one document
appears on a stream.
According to the original question, elements are streaming in, and transformed
output is to be streamed out. There is no EOF after each document.
In order to achieve the desired result, there must be some pre-parser chunking
the continuous stream into many streams, each containing a single XML
document and terminated by EOF. These individual streams can then be
handled by XSLT.
I want to use Xerces1.3 to validate a DOM using a DTD. The syntax is:
parser.setFeature("http://xml.org/sax/features/validation", true); It
seems I have to have access to internet.But how about if I can't get access
to internet? Is there any parser can do validation without having access to
internet?
Location: http://www.jguru.com/faq/view.jsp?EID=348068
Created: Mar 9, 2001 Modified: 2001-03-12 06:58:20.592
Author: JP Moresmau (http://www.jguru.com/guru/viewbio.jsp?EID=127279)
Question originally posed by Jeff C
(http://www.jguru.com/guru/viewbio.jsp?EID=346504
Yes, you need to have access to the Internet if your DTD references a URL on the
NET. The alternative is to provide your parser with a custom EntityResolver (a class
that implements the EntityResolver interface) using the
parser.setEntityResolver(EntityResolver) method. In this class, define a method :
public InputSource resolveEntity (String publicId, String systemId) throws
SAXException, IOException and return an InputSource pointing to a local DTD. The
parser will use that DTD to validate your document. Have a look at the Javadoc API
documentation for more details.
Comments and alternative answers
Feature names
Author: Doug Erickson (http://www.jguru.com/guru/viewbio.jsp?EID=1718), Mar 31,
2001
It's important to note that when setting this validation feature, the URL
"http://xml.org/sax/features/validation" is NOT opened. This string is simply used as a
name that uniquely identifies the validation feature. The name could have been simply
"validation," but using this kind of URI decreases the chance of feature name
collision.
If your document contains its own DTD or refers to a SYSTEMID accessible locally,
neither Internet connectivity nor a custom EntityResolver is required for validation.
How can we use MSXML parser from a JSP in order to... How can we use
MSXML parser from a JSP in order to transform XML file using a stylesheet
without having to use Javascript for the same?
Location: http://www.jguru.com/faq/view.jsp?EID=385296
Created: Mar 22, 2001
Author: Arun Bharathan (http://www.jguru.com/guru/viewbio.jsp?EID=106958)
Question originally posed by duds d
(http://www.jguru.com/guru/viewbio.jsp?EID=349341
Re: How can we use MSXML parser from a JSP in order to... If you are using IE 5.0
or above, return the XML to the browser with a Processing Instruction (PI) as follows
and the Browser would automatically use MSXML to generate HTML.
<?xml:stylesheet type="text/xsl" href="thexsltobeused.xsl"?>
Comments and alternative answers
msxml in java servlet
Author: Kumar Sachwani (http://www.jguru.com/guru/viewbio.jsp?EID=523774),
Oct 31, 2001
hi dude nice reply but i want to do something different i want to parse the xml
document thru my servlet and return html output to the browser can u tell me a way
thru which i can access the msxml parser just the way i access saxon or xerces in
servlets thanks kumar
BTW, who wants MSXML, use the Xerces parser from apache
How Xalan and Xerces pronounced? How Xalan and Xerces pronounced?
Location: http://www.jguru.com/faq/view.jsp?EID=403612
Created: Apr 16, 2001
Author: swarraj kulkarni (http://www.jguru.com/guru/viewbio.jsp?EID=121306)
Question originally posed by Tiger Smith
(http://www.jguru.com/guru/viewbio.jsp?EID=325564
Re: Re: How Xalan and Xerces pronounced? Put 'z' in the place of 'X' :O) Xalan -
zalan Xerces - zerces
Comments and alternative answers
Pronunciation
Author: Stephen Oakes (http://www.jguru.com/guru/viewbio.jsp?EID=406487), Apr
20, 2001
How the heck is "zerces" pronounced? :-)
It could be as in purses or as in mercies. It could even have a hard "c". I have heard
exersies and zersies.
CDATA sections are used to escape blocks of text containing characters that would
otherwise be regarded as markup. The only delimiter that is recognized in a CDATA
section is the "]]>" string that ends the CDATA section. CDATA sections can not be
nested. The primary purpose is for including material such as XML fragments,
without needing to escape all the delimiters.
Comments and alternative answers
I have the same problem, and I don't have to use CDATA section.
Author: Oscar Herrero (http://www.jguru.com/guru/viewbio.jsp?EID=1124879), Oct
30, 2003
In example, I receive this XML document. <?xml version="1.0" encoding="ISO-
8859-1"?> <xml> <nodo>...&...,<...</nodo> </xml> When I parse It with Document
doc = builder.parse ( theInputSource), the parser converts nodo to ...&...<... and I
don't want it. What can I do?
In PCDATA text, the tags inside the text will be treated as markup and entities will be
expanded, where as in CDATA, text will NOT be parsed by the XML parser.
XML Query Language Where can I learn about the efforts to create an XML-
based query language?
Location: http://www.jguru.com/faq/view.jsp?EID=414493
Created: May 3, 2001
Author: Alessandro A. Garbagnati
(http://www.jguru.com/guru/viewbio.jsp?EID=32727) Question originally posed by
John Zukowski PREMIUM (http://www.jguru.com/guru/viewbio.jsp?EID=7
There are two different XML based query languages. One is the W3C language XML-
QL (http://www.w3.org/TR/1998/NOTE-xml-ql-19980819/.
The second one is XQL (http://www.ibiblio.org/xql/).
In addition, there are few different opinions if XPath (http://www.w3.org/TR/xpath)
can be considered, or not, an XML Query language. This is mainly based on the fact
that being "[...] a language for addressing parts of an XML document. [...]", it does
much of what a query language should (and would) do.
More interestingly, the W3C announced a working draft for "XQuery: A Query
Language for XML" on February 15, 2001. XQuery is an interesting amalgam of a
SQL-like syntax grafted on to XPath. The working draft is at
www.w3.org/TR/xquery. There are some other supporting documents at
www.w3.org/XML/Query.
How can I query my xml file? For example I have this xml file:
<?xml version="1.0"?>
<bib>
<book>
<title>Harold</title>
<author>Johnson</author>
</book>
<book>
<title>Harold's Fairy Tale</title>
<author>Crockett</author>
</book>
</bib>
and I want to display the result of "author where title = 'Harold'". How
should I write the query and where I should put it, in another xml file? or
html file?
Location: http://www.jguru.com/faq/view.jsp?EID=414509
Created: May 3, 2001
Author: Chris Leonardi (http://www.jguru.com/guru/viewbio.jsp?EID=412964)
Question originally posed by Corina Stefan
(http://www.jguru.com/guru/viewbio.jsp?EID=410600
XPath provides a means of querying down into XML documents:
http://www.w3.org/TR/xpath Look at 'Location Paths' for the syntax relevant to your
particular query. Apache Xalan implements the XPath 1.0 recommendation:
http://xml.apache.org/xalan-j/index.html Typically, you'd write a XSL styelsheet that
uses an XPath expression to traverse your document tree and select the appropriate
nodes. You can also use xpath programatically from a Java class; Xalan provides an
API for that, too.
Comments and alternative answers
XSLT
Author: Kenneth Liu (http://www.jguru.com/guru/viewbio.jsp?EID=304008), May 3,
2001
It's going be hard to find books dedicated to XPath. The best information is going to
be found in books on XSLT, since XSLT and XPath are closely related.
XPath
Author: Dane Foster (http://www.jguru.com/guru/viewbio.jsp?EID=224441), Jun 25,
2001
There is a Java Library for working with XML call dom4j. It has built in support for
XPath in its DOM, so you can query any XML data-structure using XPath. Check it
out at http://www.dom4j.org
Do SAX and DOM validating parsers take the same amount of memory while
validating a document?
Location: http://www.jguru.com/faq/view.jsp?EID=414518
Created: May 3, 2001
Author: Frank Nestel (http://www.jguru.com/guru/viewbio.jsp?EID=410382)
Question originally posed by jeetendra kumar
(http://www.jguru.com/guru/viewbio.jsp?EID=410361
If you only need to validate a document and not do anything else with it, SAX does it
without actually taking memory for the document. Just implement an empty handler
which captures all SAX-events and ignores them.
All existing DOM parsers actually seem to be built on top of SAX parsers and a DOM
is a very costly (but also valuable at times) data structure in memory. DOM comes in
handy if you have to manipulate documents in memory.
Where can I learn (more) about Java's I/O (input/output, IO) capabilities?
Location: http://www.jguru.com/faq/view.jsp?EID=431192
Created: May 30, 2001
Author: John Mitchell (http://www.jguru.com/guru/viewbio.jsp?EID=4)
JSP Tutorial
Author: Steve Erbert (http://www.jguru.com/guru/viewbio.jsp?EID=291279), Jun 26,
2001
www.jsptut.com has a very good beginners introduction to JSP.
Are there any XML viewers written in JAVA that use CSS?
Location: http://www.jguru.com/faq/view.jsp?EID=434729
Created: Jun 6, 2001
Author: Luigi Viggiano (http://www.jguru.com/guru/viewbio.jsp?EID=101985)
Question originally posed by puneet suri
(http://www.jguru.com/guru/viewbio.jsp?EID=58907
I want to do is start using XML, but I cannot seem to find any of the classes
in my HP JDK.
1) To use XML, say with DOM objects, do I have to hunt around the net for
the various Java pieces, or can they be obtained from Sun directly?
2) Does SUN require other vendors to supply the XML class files, etc?
3) Is XML, a standard part of a JDK distribution?
Location: http://www.jguru.com/faq/view.jsp?EID=434732
Created: Jun 6, 2001
Author: Alessandro A. Garbagnati
(http://www.jguru.com/guru/viewbio.jsp?EID=32727) Question originally posed by
Peter Rupp (http://www.jguru.com/guru/viewbio.jsp?EID=324926
The Java API for XML Processing it's not part of the standard Jdk distribution. The
package can be downloaded from the above link (http://java.sun.com/xml/) and it
will contain the basics classes for SAX or DOM parsing of any XML compliant
document.
Comments and alternative answers
JDK 1.4
Author: Luigi Viggiano (http://www.jguru.com/guru/viewbio.jsp?EID=101985), Jun
6, 2001
Correct. And a good news: JDK 1.4 comes with JAXP and other APIs to manage
XML easily (like mapping between XML and JavaBeans etc...).
xalan:indent-amount="2"
I have a set of import dependencies between XSL files and I would like to
package them inside a jar file. If I refer to the main XSL through the
packaging directory structure so that I can use getResourceAsStream() it
fails to get the imported ones. Apparently set systemId does not work for
XSL files as resources inside a Jar file. I am using XERCES/XALAN.
Location: http://www.jguru.com/faq/view.jsp?EID=442328
Created: Jun 20, 2001 Modified: 2001-11-15 16:09:12.977
Author: Doug Erickson (http://www.jguru.com/guru/viewbio.jsp?EID=1718)
Question originally posed by Lemao Lemao
(http://www.jguru.com/guru/viewbio.jsp?EID=37814
When you supply the system ID, relative references will be resolved with respect to
it. When only the stream is provided, the processor has no idea where the data is
coming from and can't resolve relative paths.
What exactly are OASIS and ebXML? And if they are alternatives which one
should be followed?
Location: http://www.jguru.com/faq/view.jsp?EID=442329
Created: Jun 20, 2001
Author: Rahul kumar Gupta (http://www.jguru.com/guru/viewbio.jsp?EID=4809)
Question originally posed by kishan bisht
(http://www.jguru.com/guru/viewbio.jsp?EID=303016
ebXML(Electronic Business XML) is replacement for the EDI and used for the
secure exchange of buiness data. As it is an XML based so it now slowly and steadiliy
becoming an de facto for the industries
Using a SAX parser, is there a way to include a local DTD file when parsing
an XML message that doesn't contain a DOCTYPE tag?
Location: http://www.jguru.com/faq/view.jsp?EID=445798
Created: Jun 26, 2001 Modified: 2001-11-15 16:07:45.98
Author: Alessandro A. Garbagnati
(http://www.jguru.com/guru/viewbio.jsp?EID=32727) Question originally posed by
Thomas Liebmann (http://www.jguru.com/guru/viewbio.jsp?EID=315871
Hi,
There is a way to achieve that.
Check the org.xml.sax.EntityResolver interface:
If a SAX application needs to implement customized handling for external entities, it
must implement this interface and register an instance with the SAX parser using the
parser's setEntityResolver method.
The parser will then allow the application to intercept any external entities (including
the external DTD subset and external parameter entities, if any) before including
them.
Many SAX applications will not need to implement this interface, but it will be
especially useful for applications that build XML documents from databases or other
specialised input sources, or for applications that use URI types other than URLs.
Comments and alternative answers
And????
Author: Sukhbir Bassi (http://www.jguru.com/guru/viewbio.jsp?EID=986685), Aug
21, 2002
I am working on a project that has encountered this problem, and l am no further in
getting it resolved from this "answer". How would you implement the
EntityResolver? Sample code would be good.
When you talk about "parsing" you are just talking of an operation that, for example,
breaks down a text into recognized strings of characters for further analysis. With
the previous version of JAXP 1.0.x (Java API for XML Parsing), in fact, you were only
able to open and parse an XML document.
When you talk about "processing", you are talking of operations that will allow you
not just to parse, but to apply some kind of transformation to the text. Sun's has
changed the name of their API to Java Api for XML Processing, maintaining the same
acronym JAXP. The reason of this change is because the new API contains not only
the javax.xml.parser, but also the javax.xml.transform package, that are used for, by
Sun definition, "[...]processing transformation instructions, and performing a
transformation from source to result.[...]".
If you need further information, take a look at the Section 4 of JAXP 1.1
Specification
How can I pass XML generated by JSP to Cocoon for further processing?
Location: http://www.jguru.com/faq/view.jsp?EID=445943
Created: Jun 26, 2001
Author: Ethan Winograd (http://www.jguru.com/guru/viewbio.jsp?EID=295214)
Question originally posed by Radha G
(http://www.jguru.com/guru/viewbio.jsp?EID=415336
[ I am using tomcat 3.2.1 and cocoon 1.8.2. and I am using JSP's for dynamic
generation of XML. How can i give this XML output to cocoon to apply XSLT (based on
the requested client) and to give the appropriate output.]
See The Apache XML Project: How To Get Read All Over .
Cocoon allows you to take content in XML, tweak it using Java code in a "logicsheet"
and apply styling from an XSL stylesheet. This makes it easy to transform into any
SGML-like markup language; with the addition of Apache Formatting Objects
Processor (FOP), you can go right to printable PDFs.
Comments and alternative answers
Check out...
http://xml.apache.org/xerces-j/faq-write.html#faq-11
<?xml version="1.0"?>
<my_object>
<property_1>prop1value</property_1>
<property_2>prop2value</property_2>
<external_attribute name="att1Name" value="att1Value" />
<external_attribute name="att2Name" value="att2Value" />
...
</my_object>
Each "my_object" instance is stored in a record of MY_OBJECT table, and each
"external_attribute" is stored in a record of EXTERNAL_ATTRIBUTE table with an
OBJECT_ID field that chain it to the referenced object. IDs are not present in the
XML because them should be managed by the application.
You can also try some other tools mentioned here: http://www.sys-
con.com/xml/wbg/open.cfm?BType=XSLT+Utilities
Unfortunately to create XSL this way you would have to have examples of XML files
that fully exercise all allowed elements of your DTD. To come up with complete XML
that utilizes all the elements described in DTD maybe fairly difficult.
I am trying to generate an XML file using the JAXP API. From a Java
application it works correctly but when used in a JSP it gives a
SAXException. I am running JSP page on the Java Web Server. Why is this
happening?
Location: http://www.jguru.com/faq/view.jsp?EID=496270
Created: Sep 13, 2001 Modified: 2001-11-15 16:02:56.421
Author: Suresh Rangan (http://www.jguru.com/guru/viewbio.jsp?EID=308330)
Question originally posed by ramesh gudipati
(http://www.jguru.com/guru/viewbio.jsp?EID=266045
It looks like your JSP file in the webserver is not able to reach the SAXparser jar file.
Make sure the classpath is set properly before running the webserver and also
inclusion of jar file is made to the appropriate lib directory of java webserver.
Comments and alternative answers
VoiceXML also enables markup-based approaches to recognizing DTMF key input (the
tones made when you press a key on a touch tone phone handset) and recording
spoken input.
For more information on VoiceXML, please visit the related jGuru entries (search for
"VoiceXML" in all FAQs) and the VoiceXML Forum, at:
www.voicexml.org
Is there any ready made parser avaialble to parse HTML or to convert HTML
to XML or XHTML ? Basically I want to extract data from HTML.
Location: http://www.jguru.com/faq/view.jsp?EID=512157
Created: Oct 5, 2001 Modified: 2001-11-15 16:01:40.835
Author: Isaac Lopez (http://www.jguru.com/guru/viewbio.jsp?EID=460064)
Question originally posed by parul dholakia
(http://www.jguru.com/guru/viewbio.jsp?EID=451179
Try jTidy
Author: Brett Knights (http://www.jguru.com/guru/viewbio.jsp?EID=513989), Oct 8,
2001
This is available on SourceForge and includes a mode that returns an
org.w3c.dom.Document.
Perhaps a misunderstanding
Author: Bret McDanel (http://www.jguru.com/guru/viewbio.jsp?EID=704325), Dec
28, 2001
I dont think that he/she said they wanted to clean up the HTML, but instead extract
data from it. I have used the docuverse set, which takes an HTML page and allows
you to process it like an XML document. This has worked well for me in my projects,
but I am unsure if this is what you want. The URL for more information on this is
available at http://www.docuverse.com/domsdk/ I have used that to extract
information from a variety of web pages (including a custom news page where I fetch
stories from many different news sites - saves me the trouble of going to 20000 sites
to read 5 or so articles :)
How to make Tomcat use the Xerces XML parser instead of the Sun JAXP
XML parser?
Location: http://www.jguru.com/faq/view.jsp?EID=525561
Created: Oct 19, 2001 Modified: 2001-11-15 15:27:44.912
Author: Alex Chaffee (http://www.jguru.com/guru/viewbio.jsp?EID=3) Question
originally posed by suraj R (http://www.jguru.com/guru/viewbio.jsp?EID=497669
The second method is preferred, since then you can run other web applications --
and Tomcat itself -- without worrying that they're incompatible with Xalan/Xerces (or
whatever your favorite XML parser is). However, it has been known to fail, since
Classloader munging is something of a black art and hasn't always been
implemented correctly in Tomcat (or Java).
What is the relationship between the Sun Projet X library and JAXP? Is
there any other library aside from Project X which allows regestering my
own classes which are created when certain XML elements are encountered
(like factory.addMapping (props, classloader) in Project X)?
Location: http://www.jguru.com/faq/view.jsp?EID=548446
Created: Nov 15, 2001
Author: Shane Curcuru (http://www.jguru.com/guru/viewbio.jsp?EID=543803)
Question originally posed by Boris Liberman
(http://www.jguru.com/guru/viewbio.jsp?EID=333995
Project X was a parser originally available from Sun that has now been donated to
the Apache Software Foundation. See http://xml.apache.org/crimson/ for more
information on Crimson. Current (Nov-2001) releases of Crimson are used as the
reference implementation of the javax.xml.parsers package that forms half of the
JAXP 1.1 specification. Xerces is another popular Apache parser that also implements
the parsing half of JAXP 1.1.
I am trying to run this XALAN sample and I have a JSP page whicn performs
transformations, I am getting this exception
"javax.xml.transform.TransformerConfigurationException: Namespace not
supported by SAXParserNamespace " Does anybody know why??
Location: http://www.jguru.com/faq/view.jsp?EID=548448
Created: Nov 15, 2001
Author: Shane Curcuru (http://www.jguru.com/guru/viewbio.jsp?EID=543803)
Question originally posed by Amad Fida
(http://www.jguru.com/guru/viewbio.jsp?EID=19191
<example>
<element>A</element>
<element>B</element>
<element>A</element>
<element>C</element>
<element>B</element>
</example>
And produce the output (order of elements is not important, but uniqueness
is):
<example>
<element>A</element>
<element>B</element>
<element>C</element>
</example>
Location: http://www.jguru.com/faq/view.jsp?EID=548449
Created: Nov 15, 2001
Author: Nicolás Lichtmaier (http://www.jguru.com/guru/viewbio.jsp?EID=507049)
Question originally posed by Peter Mularien
(http://www.jguru.com/guru/viewbio.jsp?EID=82909
XSLT does not currently provide a direct way of extracting unique nodes from a
nodeset but that feature can be emulated. The trick would be to ask at each node if
there has been another one. This would work:
<xsl:template match="@*|node()">
<xsl:if test="not(node()) or not(preceding-
sibling::node()[.=string(current())])">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>
unique nodes
Author: Andrei Melejik (http://www.jguru.com/guru/viewbio.jsp?EID=525058), Dec
3, 2001
Another way is to use generate-id() function. Ids can be compared as strings. So that
you can filter out all the nodes but the one with the highest (lowest) id.
duplicate nodes
Author: Marian Olteanu (http://www.jguru.com/guru/viewbio.jsp?EID=453227), Jan
20, 2002
The code that you post looks only for the string value of the nodes. If you want to
look for the name, too:
<xsl:template match="@*|node()">
<xsl:if test="not(node()) or not(preceding-
sibling::node()[.=string(current()) and name()=name(current()])">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>
Anyway, "duplicate" must be defined better.
Xbeans are Java Beans. Java Bean technology supports the packaging, reuse,
connection and customization of Java code. With the appropriate set of Xbeans and a
Java Bean design tool, it is possible to build useful distributed applications with little
or no programming!
You need an implementation of the DOM and XSLT. Most Xbeans are users of the
DOM interface. They do not depend on a particular DOM implementation. The
serializer Xbean currently depends on an extension in Xerces.
We included the Xerces and Xalan implementations of the DOM and XSLT with the
Xbeans release. You can try others.
The reason for this is if an Xbean has multiple listeners for its resulting document,
the document can either be a shared, concurrently accessed document or it can be
copied for each listener. The appropriate behavior is usually not dictated by the
source Xbean but by the application itself. For example, if the multiple listeners all
read the document without modifying it, they can easily share the resulting
document. Only the application knows that the Xbeans were configured this way.
To make this explicit in the chaining of Xbeans into an application, the parallelizer
Xbean supports multiple listeners. It contains properties to indicate whether the
document should be concurrently shared among the multiple listeners or whether the
document should be copied. In case the document is concurrently shared, the
synchronizer Xbean can be used to wait until all concurrent Xbeans are done.
The sender and receiver Xbeans support the passing of XML documents across
process boundaries. There are currently three implementations of sender and
receiver using different approaches for the transport of XML. Included are an HTTP
implementation, a CORBA implementation and a RMI implementation.
How can I create an application out of Xbeans?
Location: http://www.jguru.com/faq/view.jsp?EID=585362
Created: Dec 14, 2001
Author: Bruce Martin (http://www.jguru.com/guru/viewbio.jsp?EID=12) Question
originally posed by Bruce Martin (http://www.jguru.com/guru/viewbio.jsp?EID=12
Xbeans are configured using the standard Java Bean mechanisms of property editors
and customizers. Using a Java Bean design tool, such as IBM's Visual Age for Java,
Borland's JBuilder, Symantec's Visual Cafe, FreeBuilder, NetBeans or the planned
Xbean.org configuration tool, a developer can visually instantiate, customize and
connect Xbeans. Complete applications can be created, often without writing any
code.
There are basically three ways: you can implement a useful Xbean and contribute it
to the project, you can improve an existing Xbean and contribute the changes and
you can provide us with feedback. See xbeans.org for more information.
The second release is now available at xbeans.org. It includes the following Xbeans:
translator
viewer
logger
serializer
parser
synchronizer
HTTP sender-receiver
RMI sender-receiver
CORBA sender-receiver
timer
memory meter
sample
Are there any web sites that will validate the well-formedness of an XML
document?
Location: http://www.jguru.com/faq/view.jsp?EID=747502
Created: Feb 5, 2002
Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Question
originally posed by John Zukowski PREMIUM
(http://www.jguru.com/guru/viewbio.jsp?EID=7
another link
Author: Anil Terli (http://www.jguru.com/guru/viewbio.jsp?EID=756495), Feb 12,
2002
There is another link from the ibm developer works that does the validation of an
XML. http://www.networking.ibm.com/xml/XmlValidatorForm.html
The DOM API allows for the creation of a DOCTYPE. The DOMImplementation
interface defines a createDocumentType() method. The DOMImplementation
interface can be obtained from a Document.
Comments and alternative answers
Example 10.8. A DOM program that outputs the Fibonacci numbers as a MathML
document
Could someone help me to include the doctype in the generated xml? Thanks in
advace.
While trying to find a solution for the exact mentioned problem I came upon this
site. Site URL is :
http://www.javazoom.net/services/newsletter/xmlgeneration.html
Try running the (4) example. I think it will solve your problem of including the
<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN"
"http://www.w3.org/TR/MathML2/dtd/mathml2.dtd">
What is the best way to generate a universally unique object ID? Do I need
to use an external resource like a file or database, or can I do it all in
memory?
Location: http://www.jguru.com/faq/view.jsp?EID=1030397
Created: Nov 25, 2002 Modified: 2003-02-28 08:01:34.258
Author: Alessandro A. Garbagnati
(http://www.jguru.com/guru/viewbio.jsp?EID=32727) Question originally posed by
Andy Brown (http://www.jguru.com/guru/viewbio.jsp?EID=1027054
[I need to generate unique id's that will be used for node 'ID' attribute values within
XML documents. This id must be unique system-wide. The generator must be
available to a number of servlets that add various node structures to my XML docs as
a service. What is the best way to tackle this? The 'possible' ways I can see:
• Keep the maximum ID value in a flat-file where the service would read it upon
start-up and increment it. Upon shutdown or failure, it would write the latest
max id to the file.
• Calculate the max id by searching the XML itself. This will be tougher since
XML requires an alpha-numeric value (not strictly numeric).
• Use a database (MySQL) with a two-field table where one field is the
incremental counter.
I just have this feeling that none of the above are the most efficient ways of doing
this.
Regards, -Andy]
There is an additional way to do that that doesn't rely on an external file (or
database) like the one you have presentred. If has been presented in the EJB Design
Patterns book, written by Floyd Marinescu, and available in a pdf format for free from
the given link.
The suggested solution is based on the UUID for EJB pattern, that comes out from
this question:
How can universally unique primary keys can be generated in menory without
requiring a database or a singleton?
Without enetring in the specifics (you can fully check out the pattern by reading the
appropriate chapter), the solution is to generate a 32 digit key, encoded in
hexadecimal composed as follows:
1: Unique down to the millisecond. Digits 1-8 are are the hex encoded lower 32 bits
of the System.currentTimeMillis() call.
2: Unique across a cluster. Digits 9-16 are the encoded representation of the 32 bit
integer of the underlying IP address.
3: Unique down to the object in a JVM. Digits 17-24 are the hex representation of
the call to System.identityHashCode(), which is guaranteed to return distinct
integers for distinct objects within a JVM.
• I need to generate a GUID and have seen suggestions about using an RMI
server but nothing about how to actually generate the GUID itself.
• What is the best way to provide a unique identifier as a primary key that will
work in a database independent manner? I'm looking for functionality similar
to Oracle's proprietary MY_SEQ.NEXTVAL.
• How do I automatically generate primary keys?
• and the original thread: What is the best way to implement a system-wide
object ID generator?
- Alex Chaffee]
Comments and alternative answers
Random class
Author: P Manchanda (http://www.jguru.com/guru/viewbio.jsp?EID=344357), Feb
28, 2003
Hi,
Try using the java.util.Random class to generate random numbers that can be used as
IDs.
(BTW,you don't need to use rmi nor know anything about rmi to use these classes)
-Nathan
Making it Faster
Author: Kimbo Mundy (http://www.jguru.com/guru/viewbio.jsp?EID=1120338), Oct
8, 2003
It seems to me that you could speed up the algorithm above by modifying step #4.
Instead of computing the random number every time, just compute it the first time,
and then increment it after that. 2 different JVMs should still just have a 1 in 4 billion
chance of overlap.
Millisecond overlap
Author: Thomas Paré (http://www.jguru.com/guru/viewbio.jsp?EID=1238395), Apr
14, 2005
Thanks for the very interesting pointer on 'Ejb design patterns'. I've read the
implementation details and found something troublesome.
In step 1 : "Unique down to the millisecond. Digits 1-8 are are the hex encoded lower
32 bits of the System.currentTimeMillis() call". Only the lower 32 bits of time are
considered, which makes the uniqueness of that part only valuable for a period of 50
days. Looks like a serious issue.
JAXB, should one start using the API in a live project considering the fact
that it is still in its beta? JAXB, should one start using the API in a live
project considering the fact that it is still in its beta? This will help me avoid
a lot of unnecessary code.
Location: http://www.jguru.com/faq/view.jsp?EID=1061579
Created: Feb 27, 2003
Author: Ivo Limmen (http://www.jguru.com/guru/viewbio.jsp?EID=327483)
Question originally posed by Mahendra Goyal
(http://www.jguru.com/guru/viewbio.jsp?EID=331192
JAXB is no longer a beta product. The latest version can be downloaded from Sun
packed within the Java Web Services Developer Pack 1.1. If it is a package from Sun
you can always trust the fact that the API of the early access version will be the very
much the same as the API of the official release. A lot of open source packages to
not maintain that principle but there are exceptions: Struts, Tomcat, ect.
I need to produce documents that carry those tags from the XML to the
output document.
Thanks
Andy
Location: http://www.jguru.com/faq/view.jsp?EID=1061580
Created: Feb 27, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by Andy Miscuk
(http://www.jguru.com/guru/viewbio.jsp?EID=1058721
If you don't need to validate it, you have at least two choices
You can design/constrain your upcoming XML files with DTD or schema. However,
you still need to write your own text file parser, to simply read line by line to convert
your legal documents to the desired XML documents.
This is because only you know your text file structure, and what content you want to
put where in your XML and under which tag.
XML sourece
<root>
<tagA />
<tagB />
<tagC />
<tagA />
</root>
XSLT sourece
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/root">
<newroot>
<xsl:apply-templates />
</newroot>
</xsl:template>
<xsl:template match="*">
<xsl:copy-of select="." />
</xsl:template>
<!-- do something only on the first one -->
<xsl:template match="tagA[1]" >
<hasTagA>
Do something here
</hasTagA>
</xsl:template>
<!-- do nothing on the rest -->
<xsl:template match="tagA[position() != 1]" />
</xsl:stylesheet>
XML result
<newroot>
<hasTagA>
Do something here
</hasTagA>
<tagB/>
<tagC/>
</newroot>
HTH! :)
Can I used a arbitrary defined DTD to generate all possible XML templates?
Location: http://www.jguru.com/faq/view.jsp?EID=1064578
Created: Mar 9, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by layout crazy
(http://www.jguru.com/guru/viewbio.jsp?EID=1064506
The answer is NO unless it is an extreme trivial case. See the really trivial DTD
bellow. We already have 4 possible "templates". Here we assume templates is the
right word here. I use one line for each XML file for easy listing. For a little less
trivial DTD, it is easy to imagine that all the combination and permutation will cause
an exponential explosion. I don't think you want the result, let alone having the
space to store the result or writing an application to use that result.
1. <name>some_name</name>
2. <age>some_number</age>
3. <sex>one_of_the_two</sex>
4. <person><name>some_name</name><age>some_number</age><sex>one_of_t
he_two</sex></person>
If you don't believe all four are valid against the DTD, try to validate them by
yourself .
Defining SQL statements in the DTD How do I delcare my XML embeded SQL
statements in my DTD? See original question here
Location: http://www.jguru.com/faq/view.jsp?EID=1064704
Created: Mar 10, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by Richard Cunliffe
(http://www.jguru.com/guru/viewbio.jsp?EID=1064616
I've a example about this topic, take a look, play with it a little. I believe you will get
it! That was also how I got it.
org.w3c.dom.Document.importNode(node, true)
to make the node forget its parent and switch the container Document.
Create multiple HTML files using one source XML and XSLT I would like to
generate different HTML files for 'pages' that are described in a single XML
source. Is there any way to create a new result tree in XSL for a new file? Or
is there some other technique? Thanks in advance, Brian
Location: http://www.jguru.com/faq/view.jsp?EID=1066373
Created: Mar 14, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by Brian Barran
(http://www.jguru.com/guru/viewbio.jsp?EID=1065124
Q. Can I tranform one single XML to several html files? For example, I want to
transfer each html node to an individual html file.
msxml:script is a Microsoft msxml extension, and should not be put into xsl
namespace. Someone might manipulate it into their own defined xsl namespace does
not mean you can use it generally.
w3c was try to add script as a XSL1.1 element, but there is a petition to withdraw it.
What is the final status for that? I don't know.
The source:
<env:Body>
<update xmlns="http://why.is.this.url.repeated.in.the.result">
<products>
<SomeProduct>
<ID>1</ID>
<status>active</status>
<username>someUser</username>
<password>myPassword</password>
</SomeProduct>
</products>
</update>
</env:Body>
</env:Envelope>
The XSL:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" encoding="utf-8" />
<xsl:template match="/">
<env:Envelope xsl:version="1.0"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header>
<xsl:element name="parameters">
<xsl:copy-of select="//*/*['Header'][1]/parameters/*"/>
</xsl:element>
</env:Header>
<env:Body>
<xsl:element name="update">
<xsl:element name="Product">
<xsl:copy-of select="//*/*['Header'][1]/transactionId"/>
<xsl:copy-of select="
//*/*['Body']/*/*['Products']/*[1]/*[not(name()='password' or
name()='username')]"/>
</xsl:element>
</xsl:element>
</env:Body>
</env:Envelope>
</xsl:template>
</xsl:stylesheet>
The result:
Because XSLT is doing exact the right thing! In your source, everything in your
<update> tag belong to "http://why.is.this.url.repeated.in.the.result" name space.
Therefore, those tags in your result should belong to the same namespace.
Do one of the following two will reach you "goal". The point is make those tags do
not belong to the same namespace. However, I highly suspect that is what you really
"want".
• Put xmlns="" in all tags under <update xmlns="http:..."> in you soap XML
source
• Change it to:
• <mytag:update
xmlns:mytag="http://why.is.this.url.repeated.in.the.result">
• <products>
• <SomeProduct>
• <ID>1</ID>
• <status>active</status>
• <username>someUser</username>
• <password>myPassword</password>
• </SomeProduct>
• </products>
• </mytag:update>
Both efforts are trying to make them belong to no namespace. However, if you have
default namespace defined on higher level, the second choice will make them belong
the higher-level default namespace. That is not the case for the source file you
provided. It is just a precautious warning.
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="date">DEFAULT-DATE</xsl:param>
...
DOCTYPE and "public identifier" URI I develop a web application and in the
web.xml file I must indicate a DTD. For the moment I have the following
declaration: <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD
Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> I
would like to know how is it possible to point to a local copy of the resource
for the DTD, instead of the remote one at java.sun.com ? I use Tomcat 4.0.1
as web server.
Location: http://www.jguru.com/faq/view.jsp?EID=1069080
Created: Mar 24, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by HELIGON Sandra PREMIUM
(http://www.jguru.com/guru/viewbio.jsp?EID=823885
HELIGON Sandra:
I just tried all possible options I could think of. You will have more than one choices
to do what you want. Agreed, the worst choice would be the hard-coded system
dependent path.
I want to create an XML file from a comma delimited text file I have a .txt
file which contains some atomic values separated by commas. From this .txt
file I want to create an XML file of those values. How do I do this ? Can I get
the code also ?
Location: http://www.jguru.com/faq/view.jsp?EID=1070027
Created: Mar 26, 2003
Author: Jan Matèrne (http://www.jguru.com/guru/viewbio.jsp?EID=567992)
Question originally posed by Arun V
(http://www.jguru.com/guru/viewbio.jsp?EID=1069860
Three possibilities:
lt;root>
<a>aaa|bbb|ccc|vvv|abc|</a>
</root>
I want this result
<root>
<a1>aaa</a1>
<a2>bbb</a2>
<a3>ccc</a3>
<a4>vvv</a4>
<a5>abc</a5>
</root>
Location: http://www.jguru.com/faq/view.jsp?EID=1070072
Created: Mar 26, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by Kenneth Chin
(http://www.jguru.com/guru/viewbio.jsp?EID=1060452
It is not easy, but can be done. It also requires recursion. You probably can do better
than I did, but here is a solution anyway. It might not be the greatest, but it works.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/*" >
<xsl:element name="{name()}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="a" >
<xsl:call-template name="proc" >
<xsl:with-param name="num" select="1" />
<xsl:with-param name="txt" select="text()" />
</xsl:call-template>
</xsl:template>
<xsl:template name="proc">
<xsl:param name="num" select="0"/>
<xsl:param name="txt" select="''" />
<xsl:element name="{concat('a', $num)}" >
<xsl:choose>
<xsl:when test="contains($txt, '|')" >
<xsl:value-of select="substring-before($txt, '|')"
/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$txt" />
</xsl:otherwise>
</xsl:choose>
</xsl:element>
<xsl:variable name="left" select="substring-after($txt, '|')" />
<xsl:if test="string-length($left)>1" >
<xsl:call-template name="proc" >
<xsl:with-param name="num" select="$num + 1" />
<xsl:with-param name="txt" select="$left" />
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Differences in XML files(Urgent) If i have two xml files with the same dtd
do i have any mechanism to compare those two files
and to know the changes like whether any tag is
deleted or updated or newly added.
How can i do this in common way.
Thanks in Advance
Rizwan Md.
Location: http://www.jguru.com/faq/view.jsp?EID=1070454
Created: Mar 27, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by Mohammad Rizwan
(http://www.jguru.com/guru/viewbio.jsp?EID=989793
In theory, this is the best article for the topic so far, but it is not easy to read or
implement: http://citeseer.nj.nec.com/449452.html
Enjoy!
Xerces to JAXP migration We are moving from JDK 1.2 to JDK 1.3. The XML
parser are also upgraded from Xerces to JAXP. Our application code uses
XML extensively and uses inhouse XMLParcers. I was wondering what code
chages do you think is involved in moving from Xerces to JAXP. Do anyone
have any pointers as to what changes would be. Any input is appreciated.
Thanks.
Location: http://www.jguru.com/faq/view.jsp?EID=1070755
Created: Mar 27, 2003 Modified: 2003-03-27 18:40:51.954
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by krishnan meenakshi
(http://www.jguru.com/guru/viewbio.jsp?EID=2858
1. You have concepts problems. JAXP is just standard interfaces for you to use
any JAXP compliant Java parser. And xerces is just one of them
2. When you move to JAXP, you're still using xerces as your parser unless you
want to switch vendors.
3. What you need to do? Move your code to most recent stable build xerces first.
Make as less changes as possible. Test your application during the move,
don't break your application. If something does not work, fix it.
4. Move to JAXP after that, actually not much left. Search the files for xerces.
Change them to its parent interfaces or superclass in JAXP. Change one at a
time. Don't break your application any time.
5. You need to set a system property, otherwise, your application will be
compilable, but not work.
6. -Dorg.xml.sax.driver=org.apache.xerces.parsers.SAXParser
7. If some method does not exist in JAXP or work differently in JAXP, then you
need to do more your own work to make it work in JAXP. Be conservative and
creative.
8. Good luck!
Why I know it? Since I've done it in a slight different scenario, but pretty similar.
How to reorder xml elements in the invalid XML according to the definition
of DTD?
I have some xml documents where elements appear in different order than
specified by dtd/schema, thus are not valid xml documents. What is the
best way to reorder them so they are valid? Thanks.
Location: http://www.jguru.com/faq/view.jsp?EID=1071020
Created: Mar 28, 2003 Modified: 2003-03-28 10:47:24.345
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by Cheng Fang
(http://www.jguru.com/guru/viewbio.jsp?EID=485380
XSLT will not work, since xsl does not read DTD. I search the web, and not found
anyway to enforce DTD on invalid XMLs. The reason probably very similar to this one
Q. Can I used a arbitrary defined DTD to generate all possible XML templates?
Good luck!
I have a Servlet and a Servlet Filter that is supposed to apply an xsl to it.
The transformation appears to work, I get back a transformed document,
but it appears (in IE) as if IE thinks its an HTML document (i.e., you see the
<html><body>, etc tags). Viewing source, and saving as an HTML file will
display correctly. How can I correctly set the Content Type of the response?
Location: http://www.jguru.com/faq/view.jsp?EID=1074630
Created: Apr 8, 2003
Author: Vincent Fischer (http://www.jguru.com/guru/viewbio.jsp?EID=1035285)
Question originally posed by Vincent Fischer
(http://www.jguru.com/guru/viewbio.jsp?EID=1035285
I figured this out. Many thanks go out to Matan Amir for pointing me in the right
direction.
I used Ethereal (I couldn't get tcptrace to work), to verify that in fact the content
type was "text/xml", instead of "text/html". So, I finally figured out that instead of:
response.setContentType("text/html");
I wrote:
wrapper.setContentType("text/html");
I'm guessing the reason is because the response and request objects in the Filter
cannot be modified... So instead, I made the changes to the wrapper. Of course, if
I'd set my servlet to send the response as "text/html" this would work too, but the
purpose of the assignment was to change the contentType...
How to write xslt extended method? Can you give an example? The
following of my code does not work.
java code:
import javax.xml.parsers.*;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import java.io.File;
import java.util.Date;
import org.w3c.dom.*;
root.appendChild(date);
doc.appendChild(root);
DOMSource source = new DOMSource(doc);
</xsl:element>
</xsl:template>
</xsl:stylesheet>
=======================================
runtime exception:
file:/E:/working/XML/classes/date.xsl; Line 3; Column -1;
javax.xml.transform.TransformerException: Instance
method call to method new requires an Object instance
as first argument
=================================================
===========
Please help me to resolve this problem.Thanks.
Location: http://www.jguru.com/faq/view.jsp?EID=1075928
Created: Apr 12, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by TPZ Stamp
(http://www.jguru.com/guru/viewbio.jsp?EID=465268
What you want to do does not even require a customized java extention. Simply
using java.util.Date is enough. However, if you want to format you date string
properly, then you do need to write your own class.
I found some time, and wrote 2 examples. One does what you wanted to do. The
other does more.
<h5>Java Code</h5>
package com.example;
import java.util.Date;
import java.text.SimpleDateFormat;
public class XObj {
public static String getDateString(String format) {
SimpleDateFormat df = new SimpleDateFormat(format);
return df.format(new Date());
}
}
The code can also be found at XSLT Extension, advanced topics
Enjoy!!!
I have a problem with the XML Xerces parser when namespaces are used.
If I have just one defined namespace in the root of the document, and I use
a Xpath sentence to find one of the elements in this namespace, the parser
works.
But if there are more than one defined namespaces en the root, the same
Xpath sentence doesn´t find any element!
My xml is:
</item>
</organization>
</organizations>
<resources xml:base="/resources">
<resource adlcp:scormtype="sco" href="/file1.html"
identifier="RESOURCE1" type="webcontent" xml:base="/files"/>
<resource adlcp:scormtype="asset" href="/myImage.jpg"
identifier="RESOURCE2" type="webcontent" xml:base="/images"/>
</resources>
</manifest>
Thank you very much.
Location: http://www.jguru.com/faq/view.jsp?EID=1076028
Created: Apr 13, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by Guido García
(http://www.jguru.com/guru/viewbio.jsp?EID=1011381
You need to understand how namespace and its prefix works to understand your
problem.
• All tags w/o prefix in your XML belong to the default namespace
"http://www.imsproject.org/xsd/imscp_rootv1p1p2"
• Prefix, such as "adlcp" must be defined in your xpath context before using.
• If you're using XSLT, it must be defined there. Otherwise, you need to use
namespace-uri() and local-name() functions.
• A simple example can be found here Q. How to handle attributes with
namespace in xpath?. Give it a try!
Location: http://www.jguru.com/faq/view.jsp?EID=1076214
Created: Apr 14, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by Ismail Fadal
(http://www.jguru.com/guru/viewbio.jsp?EID=494628
If you're using Java based Transformer such as xalan, then I have two complete
examples for you:
• A simple Java extension example to display today's date
• A customized Java extension example to display today's date with specified
format
Languages:Markup:XML:XSLT
Author: Dilip Beepyata (http://www.jguru.com/guru/viewbio.jsp?EID=1188055), Jul
22, 2004
Add this function in your java class - com.test.xslUtil;
How to pass output from JDOM to the next transformation etc. without
writing to a file? How to get output in JDOMStrem?
Location: http://www.jguru.com/faq/view.jsp?EID=1076223
Created: Apr 14, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by neil thompson PREMIUM
(http://www.jguru.com/guru/viewbio.jsp?EID=1053274
There is no such thing called JDOMStream. However, JDOM just uses all existing Java
IO classes as output tools, and extreamely flexible.
How to concatenate XML files There are several XML files which have same
DTD file. I need to concatenate them into 1 file. Can anyone give me a hint?
Thanks
Location: http://www.jguru.com/faq/view.jsp?EID=1077360
Created: Apr 17, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by Peter Zhang
(http://www.jguru.com/guru/viewbio.jsp?EID=1077199
Enjoy!
NullPointerException
Author: camille espanol (http://www.jguru.com/guru/viewbio.jsp?EID=1248614), Jun
14, 2005
I have NullPointerException and don't know why.
<xsl:for-each select="/loan/person">
<xsl:element name="borrower">
<<xsl:for-each select="/loan/money">
< <xsl:if test="">
< <<xsl:element name="income">
< <</xsl:element>
< <</xsl:if>
<</xsl:for-each>
</xsl:element>
</xsl:for-each>
Here is an complete answer for you, include the XMLs XSLT and analysis.
<people>
<person>
<name>John Doe</name>
<ssn>111111111</ssn>
</person>
<person>
<name>Mary May</name>
<ssn>222222222</ssn>
</person>
<income>
<ssn>111111111</ssn>
<amount>33400</amount>
</income>
<income>
<ssn>111111111</ssn>
<amount>1000</amount>
</income>
<income>
<ssn>222222222</ssn>
<amount>25000</amount>
</income>
<income>
<ssn>333333333</ssn>
<amount>40000</amount>
</income>
</people>
Required XML result
<people>
<person ssn="111111111" name="John Doe">
<income amount="33400"/>
<income amount="1000"/>
</person>
<person ssn="222222222" name="Mary May">
<income amount="25000"/>
</person>
</people>
<results>
<testResult>
<logs>
<log message="theLogMessage"/>
</logs>
<result status="-1" />
</testResult>
<testResult>
<logs>
<log message="theLogMessage"/>
</logs>
<result status="-5" />
</testResult>
<testResult>
<logs>
<log message="theLogMessage"/>
</logs>
<result status="-1" />
</testResult>
<testResult>
<logs>
<log message="theLogMessage"/>
</logs>
<result status="-5" />
</testResult>
</results>
i need output like:
status count
-1 2
-5 2
I wanna know how to count the number of an attribute with particular
values?? An early response is required...as i m stuck wit this
Location: http://www.jguru.com/faq/view.jsp?EID=1081267
Created: May 2, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by Ravi Anand
(http://www.jguru.com/guru/viewbio.jsp?EID=1079662
Here is a complete answer for you!
<results>
<result status="-1" >aaa</result>
<result status="-5" >bbb</result>
<result status="-1" >ccc</result>
<result status="-5" >ddd</result>
<result status="-5" >lll</result>
<result status="-6" >vvv</result>
<result status="-1" >vvv</result>
</results>
HTML Tag embedded in XML The client I'm working with has embedded a
<br> tag inside one of their elements in a document.
I realize this is not properly formed XML, but I can't get them to change
their minds about this.
Thanks
Stephen McConnell
Location: http://www.jguru.com/faq/view.jsp?EID=1082623
Created: May 7, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by Stephen McConnell PREMIUM
(http://www.jguru.com/guru/viewbio.jsp?EID=248618
• If you insert html, AFAIK, CDATA section is the only answer to keep your XML
file well-formed.
• If you change your html to xhtml, of course, the well-formness problems
would be solved. The next, it would be validation problems if you need to
validate your XML. :) You also can solve that problem by setting
processContents="lax" in your schema to get away from there. See Q. What
does the validator do when we set processContents="lax"?
I'm now generating a xml in to a string from database and but for many
data like 15000 data it took almost 83 minutes...
...
...
xmlString= xmlString + "<value>" + value + "</value>"
}
....
some process to transform this xmlString with xsl file and
generate report.
Location: http://www.jguru.com/faq/view.jsp?EID=1083627
Created: May 11, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by mahbub kabir
(http://www.jguru.com/guru/viewbio.jsp?EID=1083598
I guess you would never need 15000 records for XSL transform and display.
Therefore, you need only to load the data needed, and show the user. Load other
data on needed bases. This is the general concept of GoF proxy design pattern.
There are many ways to implement it. Try to find one fit your needs.
Comments and alternative answers
stringbuffer
Author: Rob Parker (http://www.jguru.com/guru/viewbio.jsp?EID=914522), May 14,
2003
One thing I noticed from your code is that you should be using a
StringBuffer instead of a string when creating your xml. Strings are
immutable, so every time you concatenate a string to itself,
you really create a new string object. This can really hurt
your performance, especially when dealing with large strings. You should change:
String myString = "";
myString = myString + "blah";
myString = myString + "blah2";
...
To:
StringBuffer sb = new StringBuffer();
sb.append("blah");
sb.append("blah2");
...
myString = sb.toString();
Rob
Re: stringbuffer
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432),
May 16, 2003
Doing this is fine
xmlString= xmlString + "<value>" + value + "</value>"
Since javac is actually using StringBuffer to do String concatendations. No extra
String object created. Check j2sdk src files for details.
<EncodingMap>
<!-- Set to the desired MIME defined in this file -->
<XmlEncoding>UTF-8</XmlEncoding>
<!-- ASCII -->
<JavaEncoding>
<JavaName>ASCII</JavaName>
<MimeName>
<Name>US-ASCII</Name>
</MimeName>
</JavaEncoding>
<!-- Latin1 -->
<JavaEncoding>
<JavaName>ISO8859_1</JavaName>
<MimeName>
<Name>ISO-8859-1</Name>
<Alias>ISO_8859-1</Alias>
<Alias>LATIN1</Alias>
<Alias>L1</Alias>
<Alias>IBM819</Alias>
<Alias>CP819</Alias>
</MimeName>
</JavaEncoding>
<!-- Latin2 -->
<JavaEncoding>
<JavaName>ISO8859_2</JavaName>
<MimeName>
<Name>ISO-8859-2</Name>
<Alias>ISO_8859-2</Alias>
<Alias>Latin2</Alias>
<Alias>L2</Alias>
<Alias>ISO-IR-101</Alias>
</MimeName>
</JavaEncoding>
</EncodingMap>
I m getting this error
ERROR: Unable to load encoding-map.xml from the CLASSPATH:
org.jdom.JDOMException: Error on line 51: Document root element
"EncodingMap", must match DOCTYPE root "EncodingMap".
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:367)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:673)
Location: http://www.jguru.com/faq/view.jsp?EID=1084018
Created: May 12, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by tech tech
(http://www.jguru.com/guru/viewbio.jsp?EID=809635
What a mess? Many things are wrong here. Don't know what is for what.
Thanks!
Comments and alternative answers
How to send a value from a Html form to an xslt HI, I have an html form
with some options , an xml file that contains many records , and an xslt file.
Now when the user selects an option in the html file then i want to pass that
value to my xslt to select only those records that matches the pattern. Is
this possible ?
Location: http://www.jguru.com/faq/view.jsp?EID=1085989
Created: May 19, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by Harini Srinivasan
(http://www.jguru.com/guru/viewbio.jsp?EID=1082961
Good question!
I need to get the href attribute from a XML document processing instruction
tag can I do this via dom/sax or should I just read in the file line by line ? I
need to get the href from
how to handle 2 xml files with one xsl file i have 2 xml files .i have to write
anxsl file,which should go through the first xml file and search for an
element and that element should be replaced with another element which is
in second xml file. pls help me.
Location: http://www.jguru.com/faq/view.jsp?EID=1087553
Created: May 23, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by srinivas rallapalli
(http://www.jguru.com/guru/viewbio.jsp?EID=1087438
You have to use some extention until next XSLT recommendation (1.1 ?). Here is an
example: http://bobcat.webappcabaret.net/javachina/faq/xslt_01.htm#xslt_ex_Q01
I'm just wondering it is logical to have both DTD and Schema for an XML?
I did that and when I parse it using Xerces, it give me a warning, saying
something like "parsing might not work properly if both DTD and Schema is
present".
Any comments?
Thanks in advance.
Location: http://www.jguru.com/faq/view.jsp?EID=1087556
Created: May 23, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by James Gordon
(http://www.jguru.com/guru/viewbio.jsp?EID=816892
It is not recommended. I made it work once, the major reason was trying to take
advantage of DTD entities. It would be easily causing confusion. It would be hard to
maintain stuff in the feature.
My suggestion: don't do it! That was not the w3c's intention either.
Writing a SAX parser that validates external schemas. Hi. Could someone
tell me how to write a SAX parser that validates an external schema? I've
previously written a parser that validates inline DTDs, but now I need to
urgently improve my existing code. Any help would be much appreciated -
I'm using Xerces and would prefer to stick to non-proprietary solutions.
Location: http://www.jguru.com/faq/view.jsp?EID=1088114
Created: May 26, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by Stephen Smith
(http://www.jguru.com/guru/viewbio.jsp?EID=1088030
That is a norm instead of exception. You only need set certain features. I've an
example here. It is using JDOM, but the process is exact the same.
If you put the second argument as *.xsd, it will use the external xsd instead of the
one specified by the XML file
how to generate xml file with only some elements of another xml file using
xsl file. I have an xml file.Now i have to write an xsl file so that,it should
copy only some elements of the input xml file. please help me.this is urgent
Location: http://www.jguru.com/faq/view.jsp?EID=1088121
Created: May 26, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by srinivas rallapalli
(http://www.jguru.com/guru/viewbio.jsp?EID=1087438
This is a summary. It just depends how many you want to copy over.
1. If you only want to copy a few, then disable all default templates and only
write the copy templates for those you want to copy.
2. If you want to copy all but exclude a few, then use identity template, and only
disable a few templates for those you want not to copy.
3. How to disable some templates? Simple:
4. <xsl:template match="tag1_to_disable|tag2_to_disable" />
5. How to write identity template?
6. <xsl:template match="*|@*|comment()|processing-instruction()|
text()">
7. <xsl:copy>
8. <xsl:apply-templates select="*|@*|comment()|processing-
instruction()|text()"/>
9. </xsl:copy>
10. </xsl:template>
11. What is copy templates?
12.<xsl:template match="tag1_to_copy|tag2_to_copy" >
13. <xsl:copy-of select="." />
14.</xsl:template>
I've built XML schemas before, and created elements that had enumerations
or attributes, but never both. What I want is something like:
<state code="1234">GA</state>
Where the "GA" value comes from an enumerated list of possible state
values. No matter what I do, I can't come up with a solution that allows me
to give the element both enumeration and an attribute. How can I make it
happen?
Location: http://www.jguru.com/faq/view.jsp?EID=1091206
Created: Jun 4, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by Jack Lamphier
(http://www.jguru.com/guru/viewbio.jsp?EID=1090448
This is a good question! When you try to enumerate base type string, you need
restriction. However, you want to add attributes to a simpleContent, you need
extension. This took me sometime to figure the answer out. It worthed the effort
anyway, since I learned a lot from the process. Here is the full xml schema solution
for the given XML, validated. The key is to separate restriction and extension.
XML Source
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="n1.xsd">
<state code="12345">TX</state>
<state code="34651">CO</state>
<state code="41562">FL</state>
<state code="28309">NJ</state>
</root>
XML Schema Source
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="state" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:complexType>
</xs:element>
<xs:simpleType name="enum">
<xs:restriction base="xs:string">
<xs:enumeration value="NJ" />
<xs:enumeration value="TX" />
<xs:enumeration value="FL" />
<xs:enumeration value="CO" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
If it is xsd:date type, empty string will not be valid. If it is xsd:string type, you can
use length or pattern facet to control it...
However, if you want to do the opposite, allowing nil value for the elements as above
defined, you need to do something special, I've an FAQ on the web, take a look:
My example somehow got cut out when the original thread was edited into the
FAQ entry:
<xs:simpleType name="acctnbrtype">
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{1,10}"/>
</xs:restriction>
</xs:simpleType>
Merging two XML documents This question is very similar to the one on
adding existing JDOM/DOM elements to a document object. I just want to
know if it is possible to combine two existing XML documents together into
a new JDOM object (i.e. a new XML file).
ex1.xml
<fruit>
<apple></apple>
</fruit>
ex2.xml
<record>
<orange></orange>
</record>
result.xml
<fruit>
<apple></apple>
<orange></orange>
</fruit>
However, if you're using DOM, clone will not work, even you set it deep. You need to
use org.w3.dom.Document.importNode() to do the same.
<items>
<item desc="BA"/>
<item desc="BE"/>
<item desc="BI"/>
<item desc="BO"/>
<item desc="BU"/>
<item desc="CA"/>
<item desc="CE"/>
<item desc="CI"/>
</items>
I have to place all items into a 5 columns and n rows table.
So the final result should be like the following:
BA BE BI BO BU
CA CE CI
I can't understand how to insert <tr> in the right place to let the table
inserts a new row when necessary.
Can somebody give me a clue ?
Thanks.
Ivan.
Location: http://www.jguru.com/faq/view.jsp?EID=1094766
Created: Jun 17, 2003
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by ivan siviero
(http://www.jguru.com/guru/viewbio.jsp?EID=781131
Here is your simple and complete answer. There is no need to do more than one
steps. You just need a little xpath trick. The output is valid xhtml as well as html.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" />
<xsl:template match="/items" >
<html>
<body >
<table border="1">
<xsl:apply-templates />
</table>
</body>
</html>
</xsl:template>
<xsl:template match="item[(position()-1) mod 5 = 0]" >
<tr>
<td><xsl:value-of select="@desc" /></td>
<xsl:for-each select="following-sibling::node()[position() <
5]">
<td><xsl:value-of select="@desc" /></td>
</xsl:for-each>
</tr>
</xsl:template>
</xsl:stylesheet>
Visit JavaChina Online
Comments and alternative answers
I want the same result of the question but in this case i have this response:
bbbcccdddeee
ggghhh
BA BE BI BO BU
CA CE CI
<xsl:value-of
<xsl:value-of select="@desc"
select="@desc"/> /> </xsl:for-
<xsl:for-each each>
select="@desc"/> </xsl:template>
<xsl:for-each <xsl:template
select="following- match="text"/>
sibling::node()[position() </xsl:stylesheet>
< 5]">
XML problem with '&' I am having a problem with XML. Whenever one of my
xml files had some data in it that contains an '&', for example <tag>
keyboard & mouse </tag> the xgen code throws an exceptions stating that
the reference cannot be found. When it hits the '&' it thinks that the value
'mouse' is a reference. Has anyone else had this problem, and does anyone
have a solution.
Location: http://www.jguru.com/faq/view.jsp?EID=1174122
Created: May 27, 2004
Author: Roseanne Zhang (http://www.jguru.com/guru/viewbio.jsp?EID=240432)
Question originally posed by logicaCMG LogicaCMG
(http://www.jguru.com/guru/viewbio.jsp?EID=1174007
use & instead. This should be used everywhere except you really have an entity
reference. It applies to html, xhtml, xml, etc.
Comments and alternative answers
Or CDATA
Author: Malachi de AElfweald
(http://www.jguru.com/guru/viewbio.jsp?EID=126518), Jul 22, 2004
I agree with using the &
however, if you are unable to for whatever reason (for example, when multiple levels
might be encoding or decoding it), you can also use a CDATA....
example:
How can I display an XML file into tree structure format using jsp on the
screen?
Location: http://www.jguru.com/faq/view.jsp?EID=1241204
Created: Apr 26, 2005 Modified: 2005-04-26 15:35:59.827
Author: Ravi Kumar Srirangam
(http://www.jguru.com/guru/viewbio.jsp?EID=1080005) Question originally posed
by rajesh k (http://www.jguru.com/guru/viewbio.jsp?EID=1240895
If you are using XSL to render the HTML, then the following link will be of some help:
http://www.15seconds.com/issue/010921.htm
converting <abc/> to <abc></abc>
I have a xml which has nodes like <abc/>. My scanner fails to recognise
them. So I need to transform the nodes <abc/> to <abc></abc> before
calling the scanner. Please help me with a regular expression. Thanks!
Location: http://www.jguru.com/faq/view.jsp?EID=1254977
Created: Jul 25, 2005
Author: Almagest FUTT (http://www.jguru.com/guru/viewbio.jsp?EID=1244568)
Question originally posed by prabha p
(http://www.jguru.com/guru/viewbio.jsp?EID=1254389
You do actually mean <abc/> when you say "singleton nodes", don't you ? For
otherwise, it wouldn't be surprising they made a fuss.
Cheers,
FUTT.
Your code
Author: Jan Matèrne (http://www.jguru.com/guru/viewbio.jsp?EID=567992), Aug 10,
2005
And don´t forget to format your code for (human) readability. Use <pre> tags for
keeping the indents and line breaks. Maybe you want to use <font color=?> for
showing difficult things.
Yep, and another tip regarding HTML here: because html tags are allowed while
posting you have to mask the html code in postings - simply replace all < by < and
it should work. Use the preview ("verify") of jGuru for checking.
Thanks Roseanne for this FAQ :-)