[Tex/LaTex] Including XML file into LaTeX

external fileslistingsxml

I am using LaTeX for very first time and have very basic knowledge about it. I am using the template from here to write my thesis. I am using Ubuntu 12.04.

When I try to include a small XML file in LaTeX with the following code, it shows the file just in one line (I am not able to see the full file in line though). But I want it to be displayed as a typical XML file (showing hierarchy).

\lstinputlisting[language=Xml]{Files/Myfile.xml}

Could someone please tell me how I can make LaTeX treat that file as an XML and show properly?

Best Answer

Try this code:

\documentclass[12pt]{amsart}
\usepackage{geometry}
\usepackage{listings}
\usepackage{color}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\geometry{a4paper}

\begin{document}

This is a sample file:

    \lstset{
    language=xml,
    tabsize=3,
    %frame=lines,
    caption=Test,
    label=code:sample,
    frame=shadowbox,
    rulesepcolor=\color{gray},
    xleftmargin=20pt,
    framexleftmargin=15pt,
    keywordstyle=\color{blue}\bf,
    commentstyle=\color{OliveGreen},
    stringstyle=\color{red},
    numbers=left,
    numberstyle=\tiny,
    numbersep=5pt,
    breaklines=true,
    showstringspaces=false,
    basicstyle=\footnotesize,
    emph={food,name,price},emphstyle={\color{magenta}}}
    \lstinputlisting{simple.xml}

\end{document}

Using the above code I have results like this:

enter image description here

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

Related Question