c# XML Schema validation

前端 未结 1 2031
难免孤独
难免孤独 2021-01-18 22:49

I have a nice XML file like this:

    
    
                 


        
相关标签:
1条回答
  • 2021-01-18 23:46

    You need to set default namespace in your xml, like this:

    <?xml version="1.0" encoding="utf-8"  ?>
        <Assets xmlns="http://tempuri.org/data.xsd">
            <Asset>
                <FileName>Boomerang - Error codes.xlsx</FileName>
                <DisplayName>Boomerang - Error codes</DisplayName>
                <Description>This is the Boomerang error codes file</Description>
                <Tags>
                    <Tag>Excel</Tag>
                    <Tag>Boomerang</Tag>
                </Tags>
                <Categories>
                    <Category>1</Category>
                    <Category>4</Category>
                </Categories>
            </Asset>
            <Asset>
                <FileName>Issue Tracker v5.xlsx</FileName>
                <Description>This is the issue tracker for Skipstone</Description>
                <Tags>
                    <Tag>Excel</Tag>
                    <Tag>Skipstone</Tag>
                </Tags>
                <Categories>
                    <Category>1</Category>
                    <Category>4</Category>
                </Categories>
            </Asset>
        </Assets>
    

    Also, there is a number of other problems:

    Path attribute is not defined in schema, 'Assetd' element is not defined. maxOccurs="unbounded" need to be set in schema for xs:element name="Asset"

    In case if you cannot modify xml, you need to remove target schema from xsd:

    <xs:schema id="data"
        xmlns:mstns="http://tempuri.org/data.xsd"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
    >
    

    And register schema like this:

    settings.Schemas.Add(null, "data.xsd");
    
    0 讨论(0)
提交回复
热议问题