Jump to content

Linefeed in XML


Patric Simon

Recommended Posts

Dear membersHow can I set a linefeed inside the texts in a node? I tried a whole day without solution... I tried <br>, , , /LF, /CR with "UTF-8" and "ISO-8859-1" encoding, but nothing happened.My XML Code (which I read in via JavaScript):<?xml version="1.0" encoding="ISO-8859-1"?><sprachumschaltung> <item1> <deutsch1>Industrie Steckverbinder</deutsch1> <englisch1>Industrial Connectors</englisch1> <franz1>Connecteurs industriels</franz1> <ita1>Connettori industriali</ita1> <spanisch1>Conectores industriales</spanisch1> </item1> <item2> <deutsch2>Steckverbinder für Automation</deutsch2> <englisch2>Connectors for Automatic Systems</englisch2> <franz2>Connecteurs pour systèmes d'automation</franz2> <ita2>Connettori per l'automazione</ita2> <spanisch2>Conectores para sistemas automàticos</spanisch2> </item2> <item3> <deutsch3>Steckverbinder für die Medizintechnik</deutsch3> <englisch3>Medical Industry Connectors</englisch3> <franz3>Connecteurs pour le domaine medical</franz3> <ita3>Connettori elettromedicali</ita3> <spanisch3>Conectores para la industria médica</spanisch3> </item3> <item4> <deutsch4>Steckverbinder für erneuerbare Energie</deutsch4> <englisch4>Connectors for Renewable Energy</englisch4> <franz4>Connecteurs pour énergies renouvelables</franz4> <ita4>Connettori per energie rinnovabili</ita4> <spanisch4>Conectores para las energías renovables</spanisch4> </item4> <item5> <deutsch5>Prüf- & Messtechnik</deutsch5> <englisch5>Test & Measurement</englisch5> <franz5>Test & Mesure</franz5> <ita5>Accessori die misure e prove</ita5> <spanisch5>Accessorios de medida y ensayo</spanisch5> </item5></sprachumschaltung>----------------------------------------------------------------------------------Here is the Javascript (which is running well, but without the linefeed...)<script language="javascript">var xmlDoc;function loadXML(){// code for IEif (window.ActiveXObject){ xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load("XML/sprachen_Introsite.xml"); getmessageE();}// code for Mozilla, Firefox, Opera, etc.else if (document.implementation && document.implementation.createDocument){ xmlDoc=document.implementation.createDocument("","",null); xmlDoc.load("XML/sprachen_Introsite.xml"); xmlDoc.onload=getmessageE;}else{ alert('Your browser cannot handle this script'); }}function getmessageE(){ document.getElementById("IS").innerHTML=xmlDoc.getElementsByTagName("englisch1")[0].childNodes[0].nodeValue; document.getElementById("AT").innerHTML=xmlDoc.getElementsByTagName("englisch2")[0].childNodes[0].nodeValue; document.getElementById("MI").innerHTML=xmlDoc.getElementsByTagName("englisch3")[0].childNodes[0].nodeValue; document.getElementById("PV").innerHTML=xmlDoc.getElementsByTagName("englisch4")[0].childNodes[0].nodeValue; document.getElementById("TM").innerHTML=xmlDoc.getElementsByTagName("englisch5")[0].childNodes[0].nodeValue;}function getmessageD(){ document.getElementById("IS").innerHTML=xmlDoc.getElementsByTagName("deutsch1")[0].childNodes[0].nodeValue; document.getElementById("AT").innerHTML=xmlDoc.getElementsByTagName("deutsch2")[0].childNodes[0].nodeValue; document.getElementById("MI").innerHTML=xmlDoc.getElementsByTagName("deutsch3")[0].childNodes[0].nodeValue; document.getElementById("PV").innerHTML=xmlDoc.getElementsByTagName("deutsch4")[0].childNodes[0].nodeValue; document.getElementById("TM").innerHTML=xmlDoc.getElementsByTagName("deutsch5")[0].childNodes[0].nodeValue;}function getmessageF(){ document.getElementById("IS").innerHTML=xmlDoc.getElementsByTagName("franz1")[0].childNodes[0].nodeValue; document.getElementById("AT").innerHTML=xmlDoc.getElementsByTagName("franz2")[0].childNodes[0].nodeValue; document.getElementById("MI").innerHTML=xmlDoc.getElementsByTagName("franz3")[0].childNodes[0].nodeValue; document.getElementById("PV").innerHTML=xmlDoc.getElementsByTagName("franz4")[0].childNodes[0].nodeValue; document.getElementById("TM").innerHTML=xmlDoc.getElementsByTagName("franz5")[0].childNodes[0].nodeValue;}function getmessageI(){ document.getElementById("IS").innerHTML=xmlDoc.getElementsByTagName("ita1")[0].childNodes[0].nodeValue; document.getElementById("AT").innerHTML=xmlDoc.getElementsByTagName("ita2")[0].childNodes[0].nodeValue; document.getElementById("MI").innerHTML=xmlDoc.getElementsByTagName("ita3")[0].childNodes[0].nodeValue; document.getElementById("PV").innerHTML=xmlDoc.getElementsByTagName("ita4")[0].childNodes[0].nodeValue; document.getElementById("TM").innerHTML=xmlDoc.getElementsByTagName("ita5")[0].childNodes[0].nodeValue;}function getmessageS(){ document.getElementById("IS").innerHTML=xmlDoc.getElementsByTagName("spanisch1")[0].childNodes[0].nodeValue; document.getElementById("AT").innerHTML=xmlDoc.getElementsByTagName("spanisch2")[0].childNodes[0].nodeValue; document.getElementById("MI").innerHTML=xmlDoc.getElementsByTagName("spanisch3")[0].childNodes[0].nodeValue; document.getElementById("PV").innerHTML=xmlDoc.getElementsByTagName("spanisch4")[0].childNodes[0].nodeValue; document.getElementById("TM").innerHTML=xmlDoc.getElementsByTagName("spanisch5")[0].childNodes[0].nodeValue;}</script>----------------------------------------------------The whole scripts are to change the Language of 5 texts on a HTML Page on the left.Also a problem is, that I set the width="150" for the text-tabletada, but after reading in and displaying the XML, the width is much wider...Thanks for answers!GreetingsPatric

Link to comment
Share on other sites

ok, I solved the problem half the way by setting a <br/> Tag where the linefeed has to be. The new problem - there must be a new one, otherwise life as a scripter would be so boring wouldn't it... - is that all the text after the <br/> is cleared or standing anywhere but in the next line... I don't know what to do next... here the code:

<?xml version="1.0" encoding="iso-8859-1"?><!--<!DOCTYPE sprachumschaltung [<!ELEMENT br EMPTY>]>--><sprachumschaltung>	<item>		<deutsch1>Industrie<br/>Steckverbinder</deutsch1>		<englisch1>Industrial<br/>Connectors</englisch1>		<franz1>Connecteurs<br/>industriels</franz1>		<ita1>Connettori<br/>industriali</ita1>		<spanisch1>Conectores<br/>industriales</spanisch1>	</item>	<item>		<deutsch2>Steckverbinder<br/>für Automation</deutsch2>		<englisch2>Connectors<br/>for Automatic Systems</englisch2>		<franz2>Connecteurs pour<br/>systèmes d'automation</franz2>		<ita2>Connettori per<br/>l'automazione</ita2>		<spanisch2>Conectores para<br/>sistemas automàticos</spanisch2>	</item>	<item>		<deutsch3>Steckverbinder für<br/>die Medizintechnik</deutsch3>		<englisch3>Medical Industry<br/>Connectors</englisch3>		<franz3>Connecteurs pour<br/>le domaine medical</franz3>		<ita3>Connettori<br/>elettromedicali</ita3>		<spanisch3>Conectores para<br/>la industria médica</spanisch3>	</item>	<item>		<deutsch4>Steckverbinder für<br/>erneuerbare Energie</deutsch4>		<englisch4>Connectors for<br/>Renewable Energy</englisch4>		<franz4>Connecteurs pour<br/>énergies renouvelables</franz4>		<ita4>Connettori per<br/>energie rinnovabili</ita4>		<spanisch4>Conectores para<br/>las energías renovables</spanisch4>	</item>	<item>		<deutsch5>Prüf- & Messtechnik</deutsch5>		<englisch5>Test & Measurement</englisch5>		<franz5>Test & Mesure</franz5>		<ita5>Accessori die<br/>misure e prove</ita5>		<spanisch5>Accessorios de<br/>medida y ensayo</spanisch5>	</item></sprachumschaltung>

The boxheight problem I solved by giving each box its fix height seperately.I hope to hear from anybody... ThanksPatric

Link to comment
Share on other sites

You don't want to put <br /> in with your XML, it's just not good practice.If you are trying to display line breaks after each element, maybe you could do that in your javascript. Rather than:

document.getElementById("IS").innerHTML = xmlDoc.getElementsByTagName("englisch1")[0].childNodes[0].nodeValue;

Try:

document.getElementById("IS").innerHTML = xmlDoc.getElementsByTagName("englisch1")[0].childNodes[0].nodeValue + "<br />";

Otherwise, you might want to look into the XSL tutorials.

Link to comment
Share on other sites

I would attempt to solve it in the display layer. If you were displaying this on a web page, you could specify that the containing element for the information be only, say, 200px wide. This would force the text to wrap somewhere in the middle of the information.I don't work much with XML these days, I'm sure someone else has a better solution for you. Maybe this link will help: http://www.xml.com/pub/a/2001/11/07/whitespace.html

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...