Altova XMLSpy 2025 Enterprise Edition 

The code listing below iterates through open documents and validates each of them. For each validation, a message is generated using the output parameters of the Validation method.

 

 

01 // An alternative iteration mode is index-based

02 // COM indices are typically zero-based

03 Documents documents = xmlSpy.getDocuments();

04 for (int i = 1; i <= documents.getCount();

05       i++)

06     {

07         Document doc = documents.getItem(i);

08

09 // Validation is one of the few methods to have output parameters.

10 // The class JVariant is the correct type for parameters in these cases.

11 // To get values back mark them with the by-reference flag.

12 JVariant validationErrorText = new

13

14 JVariant.JStringVariant("");

15

16 validationErrorText.setByRefFlag();

17       JVariant validationErrorCount = new

18

19 JVariant.JIntVariant(0);

20

21 validationErrorCount.setByRefFlag();

22       JVariant validationErrorXMLData = new

23

24 JVariant.JIDispatchVariant(0);

25

26 validationErrorXMLData.setByRefFlag();

27       if (!doc.isValid(validationErrorText,

28

29         validationErrorCount, validationErrorXMLData))

30         System.out.println("Document

31

32         " + doc.getName() + " is not wellformed - " +

33

34         validationErrorText.getStringValue());

35       else

36         System.out.println("Document

37

38         " + doc.getName() + " is wellformed.");

39     }

 

© 2018-2024 Altova GmbH