I'm checking XML files to see if elements and attributes have expected values. I have this part working.
I'm looking for a way to know if branches exist that I don't expect to be there. I'm concerned that the paths with data exist. But is there a way to determine if extra tags or branches exist that should not be in the XML file?
I just know that only certain tag names and branch combinations should appear.
It is the same situation as with looking at a screen. QTP/WinRunner can check that expected objects should be there. But it is more difficult to say if any object appears that is not in the OR or a particular list, report it.
The developers will check my QTP test script by returning broken XML. I will probably catch missing branches or incorrect elements and attributes. If they add some garbage XML such as <rubberband> </rubberband> I would not catch this. I think they are concerned about injected XML tags so I should try to handle this.
Is there a way to look for any tags and attributes that are not in an expected list?
I suppose you could create a white list of acceptable tags and check every tag to make sure it's on the list. That would be very time consuming to run.
The proper way to do this sort of thing would be to create an xsd document and validate against it. Creating an xsd is tedious, from what I've seen, but once it's created you should be able to validate your entire file against it with a few lines of code. If you're lucky, your developers already have the xsd (Schema) file created.
<font class="small">Code:</font><hr /><pre>
ValidateXML = doc.Validate(SchemaFile)
If not ValidateXML Then
For m = 1 to doc.GetValidationErrorsNumber
print "XML Validation Error", doc.GetValidationError(m)