名称不能以'3'字符开头,十六进制值0x33

时间:2013-05-28 10:12:31

标签: c# xml

xds.Data = tree.Getxml();

xds.EnableCaching = false;

treeview.DataSource = xds;

treeview.DataBind();

当我绑定树视图时,我收到此错误,我的xml在下面给出

<Spaces 
    CustomSpaceId="00000000-0000-0000-0000-000000000000" 
    CreatedUserId="1" CreatedDate="5/28/2013 3:16:32 PM" 
    SpaceType="1" 
    ParentID="00000000-0000-0000-0000-000000000000" 
    SelectAction="Select" 
    ToolTip="Shared">
    <Quick-Case 
        CustomSpaceId="fcf87b0e-b571-41dc-a880-86c26f76eda6" 
        CreatedUserId="1" CreatedDate="5/16/2007 2:28:03 PM" 
        SpaceType="2" ParentID="00000000-0000-0000-0000-000000000000" 
        SelectAction="Select" 
        ToolTip="private">
        <![CDATA[Quick-Case]]>
        <New_Space_1 
            CustomSpaceId="1b0b82d2-b1d2-4809-b152-8eba3ac335ab" 
            CreatedUserId="2" 
            CreatedDate="2/22/2013 12:23:00 PM" 
            SpaceType="2" 
            ParentID="fcf87b0e-b571-41dc-a880-86c26f76eda6" 
            SelectAction="None" ToolTip="Blocked">
            <![CDATA[New_Space_1]]>
        </New_Space_1>
    </Quick-Case>
    <Personal-Case 
        CustomSpaceId="c2fe1da8-4c36-49b3-884f-6832b508c5bd" 
        CreatedUserId="1" 
        CreatedDate="5/4/2007 12:36:07 PM" 
        SpaceType="0" 
        ParentID="00000000-0000-0000-0000-000000000000" 
        SelectAction="Select" 
        ToolTip="private">
        <![CDATA[Personal-Case]]>
    </Personal-Case>
    <3 
        CustomSpaceId="82d0be9f-030f-490b-bc4d-52b0cfcef72a" 
        CreatedUserId="1" 
        CreatedDate="5/28/2013 10:56:54 AM" 
        SpaceType="1" 
        ParentID="00000000-0000-0000-0000-000000000000" 
        SelectAction="Select" ToolTip="Shared">
        <![CDATA[3]]>
    </3>
</Spaces>

我们如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

你在最后一个内部元素中得到了无效的XML。如果需要显示3(即CDATA值),则将该值放入属性中,并为xml提供有效的元素名称。

<Spaces CustomSpaceId="00000000-0000-0000-0000-000000000000" ..snip...>
   <Quick-Case ...snip...>
       <![CDATA[Quick-Case]]>
           <New_Space_1 ...snip...>
              <![CDATA[New_Space_1]]>
           </New_Space_1>
   </Quick-Case>
   <Personal-Case CustomSpaceId="c2fe1da8-4c36-49b3-884f-6832b508c5bd" ...snip...>
      <![CDATA[Personal-Case]]>
   </Personal-Case>

   <-- THIS BLOCK IS INVALID - YOU CAN'T HAVE AN XML Element CALLED '3' -->
   <3 CustomSpaceId="82d0be9f-030f-490b-bc4d-52b0cfcef72a" ... snip...>
        <![CDATA[3]]>
   </3>
  </Spaces>