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}
}
When you add the color package and change
morestring=[b]",
into
morestring=[b][\color{red}]",
the attributes will color red.
This will color the attributes red in your xml listings.
\begin{lstlisting}[language=xml, frame=single]
<xml>
<person age="22" sex="female">Ann</person>
</xml>
\end{lstlisting}
\documentclass{article}
\usepackage{listings}
\usepackage{color}
\definecolor{lightgray}{rgb}{.7,.7,.7}
\definecolor{gray}{rgb}{.4,.4,.4}
\definecolor{darkblue}{rgb}{0,0,.3}
\begin{document}
\begin{lstlisting}[language=xml, frame=single]
<xml>
<person age="22" sex="female">Ann</person>
</xml>
\end{lstlisting}
\lstdefinelanguage{XML}
{
morestring=[b][\color{red}]",
morestring=[s]{>}{<},
morecomment=[s]{<?}{?>},
stringstyle=\color{black},
identifierstyle=\color{darkblue},
keywordstyle=\color{cyan},
morekeywords={xmlns,version,type},
backgroundcolor=\color{lightgray},
numbers=left,
numberstyle=\footnotesize\ttfamily\color{gray},
numbersep=0.5pt
}
\begin{lstlisting}[language=xml, frame=single]
<xml>
<person age="22" sex="female">Ann</person>
</xml>
\end{lstlisting}
\end{document}
\lstdefinelanguage{XML}
{
morestring=[b][\color{red}]",
morestring=[s]{>}{<},
morecomment=[s]{<?}{?>},
stringstyle=\color{black},
identifierstyle=\color{darkblue},
keywordstyle=\color{cyan},
morekeywords={xmlns,version,type},
backgroundcolor=\color{lightgray},
numbers=left,
numberstyle=\footnotesize\ttfamily\color{gray},
numbersep=0.5pt
}
Best Answer
The definition of a new command would be the easiest way to go.
Use it in your document as
\xml{tag}
.