Is it possible to create an xsd that supports a parent node and child node having the same name?
So before anyone tells me I shouldn't do this, I completely agree. However I have an xml DataFeed coming in from a third party. I already am reaching out to them to see if they can change it, 开发者_StackOverflow中文版but I figured I had better attack it from both sides.
The offending tags in the XML are as follows:
<Tags>
<TagDimension id="Topic">
<ExternalId>Topic</ExternalId>
<Tags>
<Tag>
<Label>awesome</Label>
</Tag>
</Tags>
</TagDimension>
</Tags>
I am by no means an XML/XSD whiz. My skills consist of running xsd.exe from the VS command line which brought me:
C:\temp>xsd sample.xml Microsoft (R) Xml Schemas/DataTypes support utility [Microsoft (R) .NET Framework, Version 2.0.50727.3038] Copyright (C) Microsoft Corporation. All rights reserved. Error: There was an error processing 'sample.xml'. - The table (Tags) cannot be the child table to itself in nested relations.
What's the best way to handle this?
Well I found "a way" although I am not sure it is a good way. It looks like an XSD file does not have any problems with recursively named nodes. It's just the xsd.exe tool. What I did was rename the inner <Tag>
node to <Tag2>
, which allowed me to generate the xsd file. I then opened the xsd in Visual Studio and renamed it back to <Tag>
.
It looks like this is more a result of my dependence on tools and lack of knowledge around XSD/XML, but I would love it if someone more knowledgeable would chime in on this.
精彩评论