1
加載有效的XML文檔
我的XML看起來像ConstructingParser:無法從文件
$cat /tmp/person.xml
<root xmlns="http://www.nyorg.com/metadata/config" xmlns:core="http://www.myorg.com/metadata/commonschematypes" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xschema/AppConfig.xsd">
<!-- This is important comment about person-->
<person>
<firstName>John</firstName>
<lastName>Doe</lastName>
<email>[email protected]</email>
<city>SomeWhere</city>
<property name="myName" value="someValue" />
</person>
</root>
我嘗試將其加載爲
val source = io.Source.fromURL(new java.io.File("/tmp/person.xml").toURL)
val d = scala.xml.parsing.ConstructingParser.fromSource(source, preserveWS = true)
val doc = d.document()
我看到的是
:1:1: < expected<root xmlns="http://www.nyorg.com/metadata/config" xmlns:core="http://www.myorg.com/metadata/commonschematypes" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xschema/AppConfig.xsd">^
doc: scala.xml.Document = null
在另一方面當我嘗試加載它XML.loadFile
,它的工作原理
val doc = XML.loadFile("/tmp/person.xml")
println(doc)
我看到
<root xsi:noNamespaceSchemaLocation="../xschema/AppConfig.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:core="http://www.myorg.com/metadata/commonschematypes" xmlns="http://www.nyorg.com/metadata/config">
<person>
<firstName>John</firstName>
<lastName>Doe</lastName>
<email>[email protected]</email>
<city>SomeWhere</city>
<property value="someValue" name="myName"/>
</person>
</root>
我在做什麼毛病ConstructingParser
?