【问题标题】:Having trouble implementing namespaces in XML在 XML 中实现命名空间时遇到问题
【发布时间】:2023-04-01 01:39:01
【问题描述】:

在下面的代码中,我收到“7.65GB”错误,它一直告诉我“元素“UMUC2:size”的前缀“UMUC2”未绑定”。一切看起来都正确却无法找出问题所在。

<?xml version="1.0" encoding="UTF-8"?>

<!-- New document created with EditiX at Sat Jul 05 07:35:36 AST 2014 -->

<dataCollection xmlns:UMUC1="http://umuc.edu/namespaces/games">
xmlns:UMUC2="http://umuc.edu/namespaces/software">
xmlns:UMUC3="http://umuc.edu/namespaces/music">
xmlns:UMUC4="http://umuc.edu/namespaces/video">
    <UMUC1:size>17.5GB</UMUC1:size>
    <UMUC1:date_of_collection>01/01/2013</UMUC1:date_of_collection>
    <UMUC1:collectionSite>www.google.com</UMUC1:collectionSite>
    <UMUC2:size>7.65GB</UMUC2:size>
    <UMUC2:date_of_collection>05/28/2013</UMUC2:date_of_collection>
    <UMUC2:collectionSite>www.microsoft.com</UMUC2:collectionSite>
    <UMUC3:size>100.5GB</UMUC3:size>
    <UMUC3:date_of_collection>06/26/2013</UMUC3:date_of_collection>
    <UMUC3:collectionSite>www.apple.com</UMUC3:collectionSite>
    <UMUC4:size>1.75TB</UMUC4:size>
    <UMUC4:date_of_collection>03/27/2014</UMUC4:date_of_collection>
    <UMUC4:collectionSite>www.videox.com</UMUC4:collectionSite>
</dataCollection>

【问题讨论】:

    标签: xml namespaces


    【解决方案1】:

    在您的 XML 中,UMUC2UMUC3UMUC4 前缀的声明不正确;它们被解释为元素内容。

    根元素上的命名空间声明必须如下所示(注意删除的右尖括号):

    <dataCollection xmlns:UMUC1="http://umuc.edu/namespaces/games"
                    xmlns:UMUC2="http://umuc.edu/namespaces/software"
                    xmlns:UMUC3="http://umuc.edu/namespaces/music"
                    xmlns:UMUC4="http://umuc.edu/namespaces/video">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-06
      • 1970-01-01
      • 2011-04-06
      • 1970-01-01
      • 2011-04-07
      • 2020-03-04
      • 1970-01-01
      • 2016-05-14
      相关资源
      最近更新 更多