简体   繁体   中英

Java xml-parsing using Simple returns ??? instead of greek letters

I am trying to get the values of from the following xml, but the code i've written returns a bunch of question-marks instead of what it was supposed to return. I'm guessing it must be some encoding issue, but I haven't found anything about that yet on the web.

  <channel>
    <title>ΖΩΔΙΑ Προβλέψεις, 1 Σεπτεμβρίου 2012</title>
   </channel>

zodiaClass.java

public class zodiaClass {

    @Root(strict = false)
    public static class Example {

        @Path("channel")
        @Element
        private String title;

    }

    public static void main(String[] list) throws Exception {
        Persister persister = new Persister();
        File file = new File("example1/download.xml");
        Example example = persister.read(Example.class, file);


        System.out.println(example.title);
    }
}

output:

????? ??????????, 1 ??????????? 2012

[As requested, this is a translation of the above comment thread into the form of an answer.]

I suspect that the issue is with the output, rather than with the input. Not all command-line environments support Greek. To test this, you can try System.out.println("\α") ; if your command-line supports Greek, it should show up as α (lowercase alpha).

In one of your comments, you mention that you're using Eclipse. If it does turn out that the problem is with the output, then a Google search for Eclipse console encoding suggests that there are a number of different approaches that people have tried successfully — everything from modifying the relevant Run Configuration within Eclipse to editing eclipse.ini and the system encoding .

Update: [not really an update, but I'm trying to maintain the illusion of a regular answer . . .] I see from your follow-up comment that you were able to change the console encoding by changing the encoding of the *.java file. Cool!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM