# Including XML file into LaTeX

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?

-
Are you sure that your xml file consists newlines? –  Eddy_Em Jan 11 '13 at 10:33
A've just tried 2 variants: Xml and XML works similar. –  Eddy_Em Jan 11 '13 at 10:37
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Jubobs Mar 1 at 22:30
I just wanted to advice (for people with languages like spanish,german,french) that include, > á,í,ó,Ü,etc.. inside the file xml. \lstinputlisting will give you an error referring to mathematical symbols, which can be confused. The real error are those characters. –  bheatcoker May 28 at 7:51

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,
rulesepcolor=\color{gray},
xleftmargin=20pt,
framexleftmargin=15pt,
keywordstyle=\color{blue}\bf,
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:

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

-
I am sorry but I need to ask u this silly thing. I have main file named Thesis.tex and I import different chapter files in it (like chap1.tex, chap2.tex etc.). And I want this xml file in my chap2.tex. So I am not allowed to write the code u specified over there. So where should I write it ? may be in Thesis.tex ? but then I dont want it to affect the settings adversely somewhere else. –  Ragini Jan 11 '13 at 11:19
No question is silly ;) You can do this: Add the necessary packages (i.e. listing, color, etc) to the main file. Then add the rest to the chap2.tex. I hope this solves the problem. Let me know if it's not clear. –  Pouya Jan 11 '13 at 11:27
Thanks Pouya ! I did like u said. IT shows proper colouring n all but no proper indentation, the hierarchy. May be newline character is missing or something in original file ? How to view neline symbol of file in ubuntu 12.04 ? –  Ragini Jan 11 '13 at 11:56
@Ragini listings is only choosing colours and fonts it assumes the file has been indented already. There are several tools and editors that can indent the file nicely if it is not already indented (you could get tex to parse the xml and indent but it's easier to just use an xml tool for that job) –  David Carlisle Jan 11 '13 at 12:30