使用类似 Marshal 的编码器操作 HTML

Manipulate HTML using Marshal-like encoder

我有几个 html 模板,我使用 css 选择器的组合填充它们(cascadia) and manually manipulating the html Nodes (using x/html). Is there any better way to do this ? Something like the xml.Marshaller ?

我试过使用 xhtml 和 xml 包(Decoder.AutoClose = H TMLAutoClose)但问题是在解码时很多 information/structure 丢失(即仅用于样式且未包含在数据结构中的额外 div)。

XSLT 使用模板转换 XML 数据并生成文本或 xhtml 输出。这可能适用于您的用例 https://www.w3schools.com/xml/xsl_client.asp