XML language has very limited support for keywords. You can define more keywords yourself:
\lstset{
language=XML,
morekeywords={encoding,
xs:schema,xs:element,xs:complexType,xs:sequence,xs:attribute}
}
I couldn't come up with a perfect solution right now, but juggling with the solution from what you linked and from my answer here I came up with the following, which isn't too bad:
\documentclass{book}
\usepackage{xcolor}
\usepackage{listings}
\definecolor{Maroon}{rgb}{0.5,0,0}
\definecolor{darkgreen}{rgb}{0,0.5,0}
\lstdefinelanguage{XML_android}
{
alsoletter=-,
basicstyle=\ttfamily\footnotesize,
morestring=[b]",
moredelim=*[s][\color{Maroon}]{<}{\ },
moredelim=[s][\color{Maroon}]{</}{>},
moredelim=[l][\color{Maroon}]{/>},
moredelim=[l][\color{Maroon}]{>},
morecomment=[s]{<?}{?>},
morecomment=[s]{<!--}{-->},
morecomment=[s]{<!}{>},
commentstyle=\color{darkgreen},
stringstyle=\color{blue},
identifierstyle=\color{red}
}
\lstdefinelanguage{XML_SYNTAX}{%
morekeywords={id},
alsoletter=-,
morestring=[b]",
stringstyle=\color[rgb]{0,0,1},
morecomment=[s]{<?}{?>},
morecomment=[s]{<!--}{-->},
morecomment=[s]{<!}{>},
commentstyle=\color{darkgreen},
moredelim=[s][\color{black}]{![}{]]},
moredelim=*[s][\color{Maroon}]{<}{>},
keywordstyle=\color{red}
}
\lstset{
% Basic design
backgroundcolor=\color[rgb]{0.9,0.9,0.9},
basicstyle={\small\ttfamily},
breaklines=true,
frame=l,
tabsize=2,
% Line numbers
xleftmargin={0.75cm},
numbers=left,
stepnumber=1,
firstnumber=1,
numberfirstline=true,
% HTML formatting
language=XML_SYNTAX,
}
\begin{document}
\begin{lstlisting}[%
language=XML_android,
caption={AndroidManifest.xml},
label={list:prototyp-AndroidManifest.xml}]
<!-- For own voice trigger. -->
<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
<meta-data
<!-- Reference to trigger xml -->
android:name="com.google.android.glass.VoiceTrigger"
android:resource="@xml/voice_trigger" />
\end{lstlisting}
\begin{lstlisting}[%
language=XML_SYNTAX,
caption={xml file},
label={list:arel-index.xml}]
<object id="model1">
<title><![CDATA[box]]></title>
<assets3d>
<model><![CDATA[html/resources/f50e387c699cd8c6afae2ae7c7aa3e81/box.zip]]></model>
<transform>
<translation>
<x>0.0</x>
<y>9.302986145</y>
<z>0.0</z>
</translation>
\end{lstlisting}
\end{document}
You can set the style of the [CDATA[...]]
parts as you like - since they start with <!
some care must be taken when defining comment styles..
Best Answer
Try this code:
Using the above code I have results like this:
Please note that the I've added "price", "name" and "food" as keywords. Credits for sample XML file: http://www.w3schools.com/xml/xml_examples.asp