Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

my very first xml file

Status
Not open for further replies.

tyris

Programmer
Nov 2, 2000
311
FR
hi all,
i'm creating my first xml
here is my code :

test1.xml:
<?xml version=&quot;1.0&quot;?>
<?xml-stylesheet href=&quot;display.xsl&quot; type=&quot;text/xsl&quot;?>
<BOOK>
<CHAP>
<TITLE>differents styles</TITLE>
<SUBTITLE>voici une possibilite de sous titre</SUBTITLE>
<TEXT>ici texte</TEXT>
</CHAP>
</BOOK>

display.xsl
<xsl:stylesheet xmlns:xsl=&quot;<xsl:template>
<xsl:for-each select=&quot;BOOK/CHAP&quot;>
<H1>
<xsl:value-of select=&quot;TITLE&quot;/>
</H1>
<u>
<xsl:value-of select=&quot;SUBTITLE&quot;/>
</u>
<H2>
<xsl:value-of select=&quot;TEXT&quot;/>
</H2>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

when i launch test1.xml under my browser it gives me a blank page
what is missing ?
Best regards X-),
Elise
 
and when i launch the .xsl it gives me :
- <xsl:stylesheet xmlns:xsl=&quot;- <xsl:template>
- <xsl:for-each select=&quot;LIVRE/CHAPITRE&quot;>
- <H1>
<xsl:value-of select=&quot;TITRE&quot; />
</H1>
- <u>
<xsl:value-of select=&quot;SOUSTITRE&quot; />
</u>
- <H2>
<xsl:value-of select=&quot;TEXTE&quot; />
</H2>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


what must i do if i simply want that what is in the tag TITLE SUBTITLE and TEXT is displayed ? Best regards X-),
Elise
 
i mean for explan in jsp to display data you must use this tag :
<%= %>

what about xml, how is a data displayed ? Best regards X-),
Elise
 
hello

to reply your first question :

in fact it's very simple :

you type &quot;<xsl:stylesheet xmlns:xsl=&quot;
instead of &quot;<xsl:stylesheet xmlns:xsl=&quot;
so the difference is &quot; and also the semicolon ';' at the end of the line
and it works... :)


to reply the second question :

when you try to view an xml file (a xsl file is also an xml file) without specifying an xsl file to display it (that's what you do when you launch the display.xsl file), IE use a default xsl file that display the content of the file with &quot;+&quot; and &quot;-&quot; to folder and unfolder the tags. :)

so if you to view the data in the test1.xml file this way, just remove the href=&quot;display.xsl&quot; ...


to reply the third question :

you can directly use your xml tags, as it's IE that interpret them

to conclude s-)

there is a good little book about xml that can be read easily (it's in french, i suppose you can read this language because of the xml tags that you use...)

FORMATION à ... XML, Microsoft Press, Michael J. Young

bye

manu0
 
great thanks, i made great steps today : i'm now able to make XSL DTD and XML files dynamicaly with a servlet
Best regards X-),
Elise
 
Hi there,

I am new to writing xml and I was just wondering if it's at all possible if you can convert a data file into an xml document automatically. i.e. so the data contains xml tags.

TIA

Iain
 
yep you can do it if you have a script, or a code
i do this with a servlet Best regards X-),
Elise
 
Cheers for that!!

Do you know of any sample code for this that is available so I can get an idea on how to go about programming it?

TIA again!

Iain
 
depends on what language you want to do it, i can give you sample of my code if you want, but i do it under java and specially servlets . Best regards X-),
Elise
 
That would be great if it's not too much hassle for you.

Thank you

Iain
 
okay i gonna post it if you want but tomorow (here it's already noon and i'm not a at work anymore) Best regards X-),
Elise
 
hi
sorry i meant 12 pm not noon.
here is a sample:
public StringBuffer sb_DATA= new StringBuffer(); //stringbuffer that will be sent in an xml format to the web page
private static final String s_XMLDECLARATION = &quot;<?xml version=\&quot;1.0\&quot; encoding=\&quot;ISO8859-1\&quot;?>\n&quot;;
private static final String s_XSL = &quot;\n<?xml-stylesheet type=\&quot;text/xsl\&quot; href=\&quot;\\projectquote\\display.xsl\&quot;?>\n&quot;;
sb_DATA.append(s_XMLDECLARATION);
sb_DATA.append(s_XSL);
then i make my connection and query to my database..

while (rs.next())
{
sb_DATA.append(&quot;\n<tables>\n&quot;);
sb_DATA.append(&quot;\n<table>\n&quot;);
for (int i= 1; i <= columns; i++)
{
sb_DATA.append(&quot;\n<columns>\n&quot;);
columName= meta.getColumnName(i);
if (columName != &quot;&quot;)
{
try //here in my case i make a second query for each result set, it's just an example in fact you are just concerned byt sb_DATA
{
strSQL= &quot;SELECT DISTINCT PubName, DataName FROM Data WHERE (DataName='&quot;
+ columName
+ &quot;')&quot;;
Statement stm=connSQL.createStatement();
ResultSet rset= stm.executeQuery(strSQL);
while (rset.next())
{ sb_DATA.append(&quot;\n<columnHeader text=\&quot;&quot; + rset.getString(1) + &quot;\&quot;/>\n&quot;).append(&quot;\n<column>&quot; + rs.getString(i) + &quot;</column>\n&quot;);
}
rset.close();
stm.close();
}
catch (SQLException e)
{
System.out.println(&quot;SQLException, reason : &quot; + e.getMessage()); }
}
sb_DATA.append(&quot;\n</columns>\n&quot;);
}
sb_DATA.append(&quot;\n</table>\n&quot;).append(&quot;\n</tables>\n&quot;);
}

here your XML is almost finished
just set the content type of your response in your httpservlet class:
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
....
response.setContentType(&quot;text/xml&quot;);
downloadBUFFER(response);
....
}

and here is the method i do call :
private void downloadBUFFER(HttpServletResponse response)
{
javax.servlet.ServletOutputStream servletoutputstream = response.getOutputStream(); //get an output stream
byte byteArray[] = sb_DATA.toString().getBytes();
servletoutputstream.write(byteArray); //write your string buffer in your output stream
servletoutputstream.close();
...
}

i have cutted many code here, because i tryed to give you only what you wanted
tell me if you want more explenation
i hope you also know some servlet code, or you won't understand what i've written.

hope this helps, Best regards X-),
Elise
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top