validate xml and remove invalid nodes (Full Version)

All Forums >> [Ask XML questions here] >> .NET programming discussions



Message


vabbs -> validate xml and remove invalid nodes (3 March 2008)

Hi,


I would like to validate an xml doc against an xsd and remove the invalid nodes. For eg in the below xml if any of the element data(supplier in this case) for order 3 is invalid then the validation procedure should remove that entire order element and come up with a xml doc with only valid orders. 

eg
<Orders>
<Order><id>1</id><Quantity>123</Quantity><Supplier>A</Supplier></Order>.
<Order><id>2</id><Quantity>124</Quantity><Supplier>B</Supplier></Order>.
<Order><id>3</id><Quantity>125</Quantity><Supplier></Supplier></Order>.
<Order><id>4</id><Quantity>126</Quantity><Supplier>D</Supplier></Order>.
</Orders>

could someone tell me how to do this in .NET 2.0
Thanks in advance




JohnD -> RE: validate xml and remove invalid nodes (4 March 2008)

Vabbs,

validating against a schema will tell you that something is wrong, but you will need to edit the instance some other way - for example using an XmlDocument. I don't think there is any kind of "auto correcting" function available.

Also, the schema validation will be able to you simple things (such as this element is empty) but it will not tell you other faults (such as this record already occurred).

So, (IMHO) to fix any errors you will need to edit the document in code, and to detect some sorts of errors you will also need to be in code.

John D.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.125