元素'VAST'中不允许出现属性'xsi:noNamespaceSchemaLocation'。

6

我有一个VAST XML文件,并且正在用VAST 2.0.1 xsd验证它。出现了以下错误:

元素“VAST”不允许出现属性“xsi:noNamespaceSchemaLocation”

我的VAST XML文件:

<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      version="2.0" 
      xsi:noNamespaceSchemaLocation="vast.xsd">
  <Ad id="11267375">
    <InLine>
      <AdSystem version="1.0">Sample vast</AdSystem>
      <AdTitle><![CDATA[AD_NFM3122HD.mov]]></AdTitle>
      <Description><![CDATA[<p>&nbsp;</p>]]></Description>
      <Creatives>
        <Creative sequence="1" AdID="" id="11267375">
          <Linear>
            <Duration>00:00:15</Duration>
          </Linear>
        </Creative>
      </Creatives>
    </InLine>
  </Ad>
</VAST>

VAST 2.0.1.xsd - https://github.com/chrisdinn/vast/blob/master/lib/vast_2.0.1.xsd

当我从我的VAST Xml中删除 xsi:noNamespaceSchemaLocation="vast.xsd"> 后,它可以正常工作。

我一定需要使用 xsi:noNamespaceSchemaLocation="vast.xsd"> 吗?它的用途是什么?

在其中,我需要使用哪个XSD文件名来代替 "vast.xsd"?

我正在运行Java 1.8,这是我的堆栈跟踪:

org.xml.sax.SAXParseException; cvc-complex-type.3.2.2: Attribute 'xsi:noNamespaceSchemaLocation' is not allowed to appear in element 'VAST'.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:203)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:396)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:327)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:284)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:452)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3230)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processAttributes(XMLSchemaValidator.java:2707)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:2050)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:740)
    at com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.beginNode(DOMValidatorHelper.java:277)
    at com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate(DOMValidatorHelper.java:244)
    at com.sun.org.apache.xerces.internal.jaxp.validation.DOMValidatorHelper.validate(DOMValidatorHelper.java:190)
    at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:109)
    at javax.xml.validation.Validator.validate(Validator.java:124)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.rules.Verifier$1.evaluate(Verifier.java:35)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
    at org.junit.rules.RunRules.evaluate(RunRules.java:20)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runners.Suite.runChild(Suite.java:127)
    at org.junit.runners.Suite.runChild(Suite.java:26)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:138)
    at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:62)
    at org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:139)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:103)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:74)
2个回答

1
这是您的XML修复后符合vast.xsd标准,我已经远程引用它:
<VAST xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      version="2.0" 
      xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/chrisdinn/vast/master/lib/vast_2.0.1.xsd">
  <Ad id="11267375">
    <InLine>
      <AdSystem version="1.0">Sample vast</AdSystem>
      <AdTitle><![CDATA[AD_NFM3122HD.mov]]></AdTitle>
      <Description><![CDATA[<p>&nbsp;</p>]]></Description>
      <Survey/>
      <Error/>
      <Impression/>
      <Creatives>
        <Creative sequence="1" AdID="" id="11267375">
          <Linear>
            <Duration>00:00:15</Duration>
          </Linear>
        </Creative>
      </Creatives>
    </InLine>
  </Ad>
</VAST>

我已添加了XSD所需的一些元素,但即使没有这些添加,您也不应该收到报错信息:

在元素'VAST'中不允许出现属性“xsi:noNamespaceSchemaLocation”

如果您仍然在使用上述XML时收到此错误,请发表评论说明错误来自哪个软件。


更新:还是不起作用吗?

如果您正在Java代码中指定XSD的位置,

Schema schema = schemaFactory.newSchema(new URL(getSchemaURLString()));

如果您希望使用 xsi:noNamespaceSchemaLocation,请尝试删除基于Java的XSD位置说明:
Schema schema = schemaFactory.newSchema();

我在使用以上的XML时仍然遇到了相同的错误。我正在运行Java“1.8.0_72”。我的问题类似于这个:https://dev59.com/jlTTa4cB1Zd3GeqPtpES。但是我还没有尝试过在Java 1.5或低于1.8的版本中运行。 - Galet
如果这没有帮助,我们需要看到一个“最小可复现示例”。谢谢。 - kjhughes

0

这种情况曾经发生在我身上,因为在

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

我写的部分是http//而不是http://。这表明当验证器无法找到我所引用的命名空间时,错误被抛出,并且因此无法验证xsi:noNamespaceSchemaLocation属性(因为它也在xsi中)。

如果命名空间URL正确(在您的XML中看起来确实正确),那么可能表明它无法找到版本。

如果我处于这种情况下,我可能会删除版本属性(我不知道是否有2.0版本),确认版本号是否正确或使用xsi:version作为尝试的可能事项。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接