相关疑难解决方法(0)

Scala XML.loadString vs文字表达式

我一直在尝试使用Scala和XML,我发现使用XML.load(或loadString)创建的XML标记与将其写为文字的行为之间存在奇怪的差异.这是代码:

import scala.xml._
// creating a classical link HTML tag
val in_xml = <link type="text/css" href="/css/main.css" rel="stylesheet" xmlns="http://www.w3.org/1999/xhtml"></link>
// The same as a String
val in_str = """<link type="text/css" href="/css/main.css" rel="stylesheet" xmlns="http://www.w3.org/1999/xhtml"></link>"""
// Convert the String into XML
val from_str = XML.loadString(in_str)

println("in_xml  : " + in_xml)
println("from_str: "+ from_str)
println("val_xml == from_str: "+ (in_xml == from_str))
println("in_xml.getClass() == from_str.getClass(): " +
  (in_xml.getClass() == from_str.getClass()))
Run Code Online (Sandbox Code Playgroud)

在这里,输出:

in_xml  : <link href="/css/main.css" rel="stylesheet" type="text/css" xmlns="http://www.w3.org/1999/xhtml"></link>
from_str: <link rel="stylesheet" href="/css/main.css" type="text/css" xmlns="http://www.w3.org/1999/xhtml"></link>
val_xml …
Run Code Online (Sandbox Code Playgroud)

xml string comparison scala transformation

8
推荐指数
1
解决办法
1万
查看次数

scala - XML插入/更新

你知道根据XPath插入和(或)更新节点的任何Scala API吗?例如,对于给定的Node和XPath,此API将使用新节点创建XML的副本

谢谢

xml xpath scala insert

5
推荐指数
2
解决办法
1347
查看次数

标签 统计

scala ×2

xml ×2

comparison ×1

insert ×1

string ×1

transformation ×1

xpath ×1