SimpleXML 如何在 android 代码中转换它?
SimpleXML How to Transform this in android code?
@Root
public class DataSet {
@Namespace()
@Path("")
private String WordKey;
private String Pron;
private String Orig;
private String Trans;
}
我想使用 retrofit2
和 simplexml
来转换 http 请求。这是 android 代码。我在转换 xml 时遇到了麻烦。如何改造这个?我怎么写 class ?
<DataSet xmlns="http://WebXml.com.cn/">
<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="Dictionary">...</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<Dictionary xmlns="">
<Trans diffgr:id="Trans1" msdata:rowOrder="0">
<WordKey>hello</WordKey>
<Pron>'heləu, he'ləu</Pron>
<Info/>
<Translation>int.(见面打招呼或打电话用语)喂,哈罗</Translation>
<Mp3>1059.mp3</Mp3>
</Trans>
<Sentence diffgr:id="Sentence1" msdata:rowOrder="0">
<Orig>
She actually condescended to say hello to me in the street today.
</Orig>
<Trans>她今天在街上竟能屈尊跟我打招呼.</Trans>
</Sentence>
<Sentence diffgr:id="Sentence2" msdata:rowOrder="1">
<Orig>
I said hello to her, but she ignored me completely!
</Orig>
<Trans>我向她打招呼, 可她根本不理我!</Trans>
</Sentence>
<Sentence diffgr:id="Sentence3" msdata:rowOrder="2">
<Orig>Hello there, what a coincidence!</Orig>
<Trans>你好,真巧啊!</Trans>
</Sentence>
</Dictionary>
</diffgr:diffgram>
</DataSet>
通过跳过 xs:schema
和 diffgr:diffgram
找到解决方案,如下所示:
@Root(name = "DataSet", strict = false)
@Namespace(reference = "http://WebXml.com.cn/")
public class DataSet {
@Path("diffgr:diffgram[1]")
@Element(name = "Dictionary", required = false)
private Dictionary dictionary;
}
@Root
public class DataSet {
@Namespace()
@Path("")
private String WordKey;
private String Pron;
private String Orig;
private String Trans;
}
我想使用 retrofit2
和 simplexml
来转换 http 请求。这是 android 代码。我在转换 xml 时遇到了麻烦。如何改造这个?我怎么写 class ?
<DataSet xmlns="http://WebXml.com.cn/">
<xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="Dictionary">...</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<Dictionary xmlns="">
<Trans diffgr:id="Trans1" msdata:rowOrder="0">
<WordKey>hello</WordKey>
<Pron>'heləu, he'ləu</Pron>
<Info/>
<Translation>int.(见面打招呼或打电话用语)喂,哈罗</Translation>
<Mp3>1059.mp3</Mp3>
</Trans>
<Sentence diffgr:id="Sentence1" msdata:rowOrder="0">
<Orig>
She actually condescended to say hello to me in the street today.
</Orig>
<Trans>她今天在街上竟能屈尊跟我打招呼.</Trans>
</Sentence>
<Sentence diffgr:id="Sentence2" msdata:rowOrder="1">
<Orig>
I said hello to her, but she ignored me completely!
</Orig>
<Trans>我向她打招呼, 可她根本不理我!</Trans>
</Sentence>
<Sentence diffgr:id="Sentence3" msdata:rowOrder="2">
<Orig>Hello there, what a coincidence!</Orig>
<Trans>你好,真巧啊!</Trans>
</Sentence>
</Dictionary>
</diffgr:diffgram>
</DataSet>
通过跳过 xs:schema
和 diffgr:diffgram
找到解决方案,如下所示:
@Root(name = "DataSet", strict = false)
@Namespace(reference = "http://WebXml.com.cn/")
public class DataSet {
@Path("diffgr:diffgram[1]")
@Element(name = "Dictionary", required = false)
private Dictionary dictionary;
}