Skip to content

Commit a30abab

Browse files
author
Ron Petrusha
authored
Revised examples to include output (#928)
1 parent c5217ae commit a30abab

File tree

3 files changed

+51
-22
lines changed

3 files changed

+51
-22
lines changed

snippets/cpp/VS_Snippets_Data/XmlReader_Validate_SchemaSet/CPP/XmlReader_Validate_SchemaSet.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ using namespace System::IO;
1010
// Display any validation errors.
1111
static void ValidationCallBack( Object^ /*sender*/, ValidationEventArgs^ e )
1212
{
13-
Console::WriteLine( L"Validation Error: {0}", e->Message );
13+
Console::WriteLine( L"Validation Error:\n {0}", e->Message );
14+
Console::WriteLine();
1415
}
1516

1617
int main()
@@ -25,7 +26,7 @@ int main()
2526
XmlReaderSettings^ settings = gcnew XmlReaderSettings;
2627
settings->ValidationType = ValidationType::Schema;
2728
settings->Schemas = sc;
28-
settings->ValidationEventHandler += gcnew ValidationEventHandler( ValidationCallBack );
29+
settings->ValidationEventHandler += gcnew ValidationEventHandler(ValidationCallBack);
2930

3031
// Create the XmlReader object.
3132
XmlReader^ reader = XmlReader::Create( L"booksSchemaFail.xml", settings );
@@ -36,4 +37,14 @@ int main()
3637

3738
return 1;
3839
}
40+
// The example displays output like the following:
41+
// Validation Error:
42+
// The element 'book' in namespace 'urn:bookstore-schema' has invalid child element 'author'
43+
// in namespace 'urn:bookstore-schema'. List of possible elements expected: 'title' in
44+
// namespace 'urn:bookstore-schema'.
45+
//
46+
// Validation Error:
47+
// The element 'author' in namespace 'urn:bookstore-schema' has invalid child element 'name'
48+
// in namespace 'urn:bookstore-schema'. List of possible elements expected: 'first-name' in
49+
// namespace 'urn:bookstore-schema'.
3950
//</snippet1>
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
//<snippet1>
1+
// <Snippet1>
22
using System;
33
using System.Xml;
44
using System.Xml.Schema;
55
using System.IO;
66

7-
public class Sample {
8-
7+
public class Sample
8+
{
99
public static void Main() {
1010

1111
// Create the XmlSchemaSet class.
@@ -18,19 +18,28 @@ public static void Main() {
1818
XmlReaderSettings settings = new XmlReaderSettings();
1919
settings.ValidationType = ValidationType.Schema;
2020
settings.Schemas = sc;
21-
settings.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack);
21+
settings.ValidationEventHandler += ValidationCallBack;
2222

2323
// Create the XmlReader object.
2424
XmlReader reader = XmlReader.Create("booksSchemaFail.xml", settings);
2525

2626
// Parse the file.
2727
while (reader.Read());
28-
2928
}
3029

3130
// Display any validation errors.
3231
private static void ValidationCallBack(object sender, ValidationEventArgs e) {
33-
Console.WriteLine("Validation Error: {0}", e.Message);
32+
Console.WriteLine($"Validation Error:\n {e.Message}\n");
3433
}
3534
}
36-
//</snippet1>
35+
// The example displays output like the following:
36+
// Validation Error:
37+
// The element 'book' in namespace 'urn:bookstore-schema' has invalid child element 'author'
38+
// in namespace 'urn:bookstore-schema'. List of possible elements expected: 'title' in
39+
// namespace 'urn:bookstore-schema'.
40+
//
41+
// Validation Error:
42+
// The element 'author' in namespace 'urn:bookstore-schema' has invalid child element 'name'
43+
// in namespace 'urn:bookstore-schema'. List of possible elements expected: 'first-name' in
44+
// namespace 'urn:bookstore-schema'.
45+
// </Snippet1>
Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
'<snippet1>
2-
Imports System
1+
' <Snippet1>
32
Imports System.Xml
43
Imports System.Xml.Schema
54
Imports System.IO
65

7-
public class Sample
8-
9-
public shared sub Main()
6+
Public Module Sample
7+
Public Sub Main()
108

119
' Create the XmlSchemaSet class.
1210
Dim sc as XmlSchemaSet = new XmlSchemaSet()
@@ -24,14 +22,25 @@ public class Sample
2422
Dim reader as XmlReader = XmlReader.Create("booksSchemaFail.xml", settings)
2523

2624
' Parse the file.
27-
while reader.Read()
28-
end while
25+
While reader.Read()
26+
End While
2927

30-
end sub
28+
End Sub
3129

3230
' Display any validation errors.
33-
private shared sub ValidationCallBack(sender as object, e as ValidationEventArgs)
34-
Console.WriteLine("Validation Error: {0}", e.Message)
35-
end sub
36-
end class
37-
'</snippet1>
31+
Private Sub ValidationCallBack(sender as object, e as ValidationEventArgs)
32+
Console.WriteLine($"Validation Error:{vbCrLf} {e.Message}")
33+
Console.WriteLine()
34+
End Sub
35+
End Module
36+
' The example displays output like the following:
37+
' Validation Error:
38+
' The element 'book' in namespace 'urn:bookstore-schema' has invalid child element 'author'
39+
' in namespace 'urn:bookstore-schema'. List of possible elements expected: 'title' in
40+
' namespace 'urn:bookstore-schema'.
41+
'
42+
' Validation Error:
43+
' The element 'author' in namespace 'urn:bookstore-schema' has invalid child element 'name'
44+
' in namespace 'urn:bookstore-schema'. List of possible elements expected: 'first-name' in
45+
' namespace 'urn:bookstore-schema'.
46+
' </Snippet1>

0 commit comments

Comments
 (0)