小编aog*_*gan的帖子

有没有办法在Linq-to-XML查询中仅使用本地名称检索元素?

让我们假设我们有这个xml:

<?xml version="1.0" encoding="UTF-8"?>
<tns:RegistryResponse status="urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Failure"
    xmlns:tns="urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0"
    xmlns:rim="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0">
    <tns:RegistryErrorList highestSeverity="">
        <tns:RegistryError codeContext="XDSInvalidRequest - DcoumentId is not unique."
            errorCode="XDSInvalidRequest"
            severity="urn:oasis:names:tc:ebxml-regrep:ErrorSeverityType:Error"/>
    </tns:RegistryErrorList>
 </tns:RegistryResponse>
Run Code Online (Sandbox Code Playgroud)

要检索RegistryErrorList元素,我们可以这样做

XDocument doc = XDocument.Load(<path to xml file>);
XNamespace ns = "urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0";
XElement errorList = doc.Root.Elements( ns + "RegistryErrorList").SingleOrDefault();
Run Code Online (Sandbox Code Playgroud)

但不是这样的

XElement errorList = doc.Root.Elements("RegistryErrorList").SingleOrDefault();
Run Code Online (Sandbox Code Playgroud)

有没有办法在没有元素名称空间的情况下进行查询.基本上是在XPath中使用local-name()有一些特别相似的东西(即//*[local-name()='RegistryErrorList'])

linq-to-xml

9
推荐指数
1
解决办法
3020
查看次数

6
推荐指数
1
解决办法
2227
查看次数

如何使用 scala.js 读取文本文件?

基本上我想弄清楚我需要传递给该onload()方法的内容

def selectedFile(e: ReactEventI) = {
  val reader = new dom.FileReader()
  reader.readAsText(e.currentTarget.files.item(0))
  reader.onload(
  ) 
}
Run Code Online (Sandbox Code Playgroud)

scala scala.js

3
推荐指数
1
解决办法
1803
查看次数