如何使用 MACROMAN 编码解析 xml

我试图解析给定的pom内容,但出错了:xml:打开字符集“MACROMAN”:不支持的字符集:“MACROMAN”。我试图通过设置解码器来禁用严格编码。严格 = 假,但这也不起作用。


这是Go Playground链接,我正在解析这个特定的pom。任何帮助/参考将不胜感激。


<?xml version="1.0" encoding="MACROMAN"?>

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

 <parent>

   <groupId>org.eclipse.vorto</groupId>

   <artifactId>org.eclipse.vorto.parent</artifactId>

   <version>0.10.0.M1</version>

 </parent>

 <modelVersion>4.0.0</modelVersion>

 <artifactId>generators</artifactId>

 

 <name>Eclipse Vorto Code Generators</name>

 <packaging>pom</packaging>

 <modules>

        <module>org.eclipse.vorto.codegen.thingworx</module>

        <module>org.eclipse.vorto.codegen.javabean</module>

        <module>org.eclipse.vorto.codegen.mqtt</module>

        <module>org.eclipse.vorto.codegen.webui</module>

        <module>org.eclipse.vorto.codegen.webdevice</module>

        <module>org.eclipse.vorto.codegen.markdown</module>

        <module>org.eclipse.vorto.codegen.ios</module>

        <module>org.eclipse.vorto.codegen.latex</module>

        <module>org.eclipse.vorto.codegen.bosch.things</module>

        <module>org.eclipse.vorto.codegen.coap</module>

        <module>org.eclipse.vorto.codegen.aws</module>

        <module>org.eclipse.vorto.codegen.lwm2m</module>

        <module>org.eclipse.vorto.codegen.prosystfi</module>

        <module>org.eclipse.vorto.codegen.kura</module>

 </modules>

 

</project>

`


至尊宝的传说
浏览 234回答 1
1回答

隔江千里

以下是 Go 中编码的已知别名:macintoshvar nameMap = map[string]htmlEncoding{&nbsp; &nbsp; // ...&nbsp; &nbsp; "csmacintosh":&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;macintosh,&nbsp; &nbsp; "mac":&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;macintosh,&nbsp; &nbsp; "macintosh":&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;macintosh,&nbsp; &nbsp; "x-mac-roman":&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;macintosh,&nbsp; &nbsp; // ...}由于 不在该列表中,因此您可以使用函数字段通过设置macromanCharsetReader&nbsp; &nbsp; decoder.CharsetReader = charsetReader在哪里:charsetReaderfunc charsetReader(charset string, input io.Reader) (io.Reader, error) {&nbsp; &nbsp; if isCharsetMacintosh(charset) {&nbsp; &nbsp; &nbsp; &nbsp; return transform.NewReader(input, charmap.Macintosh.NewDecoder()), nil&nbsp; &nbsp; }&nbsp; &nbsp; return input, nil}var macNames = []string{&nbsp; &nbsp; "macroman",&nbsp; &nbsp; "csmacintosh",&nbsp; &nbsp; "mac",&nbsp; &nbsp; "macintosh",&nbsp; &nbsp; "x-mac-roman",}func isCharsetMacintosh(charset string) bool {&nbsp; &nbsp; charset = strings.ToLower(charset)&nbsp; &nbsp; for _, n := range macNames {&nbsp; &nbsp; &nbsp; &nbsp; if charset == strings.ToLower(n) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return true&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; return false}如果您需要更多信息,这里的答案可能会有所帮助:在Go中取消ISO-8859-1 XML输入。查看函数的源代码并遵循函数调用也很有帮助。charset.NewReaderLabel
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go