To hightlight an XML code I have refer to XML syntax highlighting, so I write:
\documentclass[10pt]{beamer}
\usepackage{listings}
\usepackage{color}
\definecolor{gray}{rgb}{0.4,0.4,0.4}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\definecolor{cyan}{rgb}{0.0,0.6,0.6}
\lstset{
basicstyle=\ttfamily,
columns=fullflexible,
showstringspaces=false,
commentstyle=\color{gray}\upshape
}
\lstdefinelanguage{XML}
{
morestring=[b]",
morestring=[s]{>}{<},
morecomment=[s]{<?}{?>},
stringstyle=\color{black},
identifierstyle=\color{darkblue},
keywordstyle=\color{cyan},
morekeywords={xmlns,version,type}% list your attributes here
}
\begin{document}
\begin{frame}[fragile]{Structure}
\lstset{language=XML}
\begin{lstlisting}
<?xml version="1.0" encoding="iso-8859-1"?>
<country>
<name> France </name>
<city> Paris </city>
<region>
<name> Nord-Pas De Calais </name>
<population> 3996 </population>
<city> Lille </city>
</region>
<region>
<name> Valle du Rhone </name>
<city> Lyon </city>
<city> Valence </city>
</region>
</country>
\end{lstlisting}
\end{frame}
\end{document}
Now I want to put in evidence some tags, color them or put them in a color rectangle, I looked for this two posts Mark a pseudocode block and insert comments near it or Beamer – Source code highlighting/annotation tips but I did not understand how it works.
Best Answer
To answer this question, I started from Mark a pseudocode block and insert comments near it. I think it is even possible to adopt Daniel's method as shown in Beamer - Source code highlighting/annotation tips (maybe in the future I'll complete the answer also in that way).
The key point, with this approach, is to use an escape character inside the
lstlisting
environment. This could be done by means of:Here is the complete code:
which gives: