0

I am writing a document which has both java and xml codes, I managed to highlight my java code but unfortunately I was unable to do the same with xml, so far I have tried more than one way either by including the style set or by modifying the lstlisting file and add key words, I dont know what is the issue exactly my xml code still not highlighted !!!! I appreciate any support Thanks in advance !

1

As you haven't supplied a minimal working example it is not clear what you have tried, but doesn't specifying the language for each listing environment do what you want? For example, you can highlight the following java and xml code snippets like this

enter image description here

by typing:

\documentclass{article}
\usepackage{listings,color}
\begin{document}

\lstloadlanguages{javascript,xml}

\begin{lstlisting}[language=java]
  public class HelloWorld
  {
    public static void main(String[] args) {
      System.out.println("Hello World!");
    }
  }
\end{lstlisting}

\begin{lstlisting}[language=xml]
  <?xml version="1.0" encoding="UTF-8"?>
  <addresses>
    <address>
      <name>Joe Tester</name>
      <street>Baker street 5</street>
    </address>
  </addresses>
\end{lstlisting}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.