Hi All,

I am a unix script debeloper and I am very new to html coding with basic awarness of syntax. My question is how to add html attributes inside the paragraph which actually contains my XML data?

<LIST>
  <ControlSegment
    TABLENAME="QueueGeneric"
    CLIENT="PST"
    DOCUMENTSTATUS=""
    PARTNERTYPE="TP"
    EDITXM="410"
    EDIVERSION="005010"
    EDIMESSAGETYPE="4100"
    EDIMESSAGECODE=""/>
</LIST>

When I add <font color="red"> they are bypassed and the same is displaying in my output also like below.

<LIST>
  <ControlSegment
   <font color="red"> TABLENAME="QueueGeneric"</font>
    CLIENT="PST"
    DOCUMENTSTATUS=""
    PARTNERTYPE="TP"
    EDITXM="410"
    EDIVERSION="005010"
    EDIMESSAGETYPE="4100"
   <font color="red"> EDIMESSAGECODE="" </font> />
</LIST>

I would much appreciate any help to resolve this.

Thanks,
Badhrish

To add styling to XML tags, you would use an external CSS file which you call at the top of your XML document like so:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="list.css"?>

But... as far as I know you can't style those attributes seperatly as in your example.

You can style the <list> and <ControlSegment /> as a whole, but if you want to style those attributes seperatly, they have to be in there own XML tags.

http://www.xmlplease.com/xmlcss

Hope this helps a bit!

I personally think that the best way to style your xml file is by using an xslt file.
According to W3Schools: "XSLT (eXtensible Stylesheet Language Transformations) is the recommended style sheet language for XML."
You can start your reading from here: http://www.w3schools.com/xml/xml_xsl.asp
Using this way of styling you have a great deal of versatality and many ways to manipulate your xml file.

Member Avatar for diafol

A bit unclear what you're trying to do.
Are you building the XML file from scratch or trying to edit an existing one?
The XMl in your second snippet is obviously wrong as you can't have a tag inside the tag as an attribute.
As mentioned, the attributes will not be coloured individually.
If you don't mind me asking, how are you going to use this XML file and why do you need to colour bits of it?

Hi diafol,
Am trying to edit the exsisting XML file apply the html attributes dynamically. This is required because my script output is nothing but the difference between two files and i am appending the records that has discripancy with Font tags. Unfortunatley font tags are not read as html, but they appear as such in the output.

Hi tdrosiadis,
Thanks for your time. The tricky part is XML should be read as a paragraph, not as XML. For your more understanding the XML file of mine is the difference between two files. I have attached a file how it should look like.

Member Avatar for diafol

Ah. OK so you're outputting as raw text. You may need to use html_encode() on the XML before applying the font tags. However, font tags have been deprecated. Use span tags either with a class (linked to CSS rule) or with the inline style attribute.

So you'll probably need an output like this:

&lt;LIST&gt;
  &lt;ControlSegment
   <span style="color:red;">TABLENAME=&quot;QueueGeneric&quot;</span>
    CLIENT=&quot;PST&quot;
    DOCUMENTSTATUS=&quot;&quot;
    PARTNERTYPE=&quot;TP&quot;
    EDITXM=&quot;410&quot;
    EDIVERSION=&quot;005010&quot;
    EDIMESSAGETYPE=&quot;4100&quot;
   <span style="color:red;"> EDIMESSAGECODE=&quot;&quot; </span>
&lt;/LIST&gt;

//EDIT

Sorry, I assumed you were using PHP. However any language should be able to encode the "html/xml". You could even do this in javascript using replacements with or without regex.

Using <pre> tags will ensure that you don't need to place <p> or <br /> tags throughout...

<pre>
&lt;LIST&gt;
  &lt;ControlSegment
   <span style="color:red;">TABLENAME=&quot;QueueGeneric&quot;</span>
    CLIENT=&quot;PST&quot;
    DOCUMENTSTATUS=&quot;&quot;
    PARTNERTYPE=&quot;TP&quot;
    EDITXM=&quot;410&quot;
    EDIVERSION=&quot;005010&quot;
    EDIMESSAGETYPE=&quot;4100&quot;
   <span style="color:red;"> EDIMESSAGECODE=&quot;&quot; </span>
&lt;/LIST&gt;
</pre>

Thanks diafol. I managed to encode my XML whcih converted all symbols < and > into underlying code &lt; &gt; via my unix script before applying html tags. This helped HTML tags to be actually applied this time to the raw data and in broswer I could see my XML as such. The output is just beautiful to watch.

Member Avatar for diafol

Awesome! Glad you got it fixed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.