threre is an effective way to validate XML in CF I tried to validate it using XmlReaderSettings but it is not effective. So someone knows how to validate an XML
It does validate. I've just run the code from the sample on device (adjusted for paths and luck of console). Sure enough it shows expected message about attribute. Here’s my code (add two buttons and a textbox to the form, also add XML and XSD files to your project, set action to “Content” and condition to “Deploy always”):
Hi thanks for your help. I only copied the file in the same directory of the exe. I tried to launch this example before local to my computer (by double clicking on the .exe). And it doesn't give any error.
When I try to deploy it on the device it doesn't found the file but they are in the same folder...
It could not possibly display any errors as PPC 2003 has no console. Change the code to pop up a message box or set a breakpoint in debugger.< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Device has no support for relative paths so putting files to the EXE folder won’t do you any good. Full path has to be specified or files won't be found.
One more thing: for some reasons many developers believe device can see desktop’s hard drive by simply specifying “C:\path\file”.
That is of course not the case – device can’t see desktop’s hard drive. So please make sure files are on device file system.
Very thanks. Looking at the doc I believe this rule are contained in the assembly is correct
Ok another thing. This strategy to use XML for configuration of my app (Tomcat like) is the more appropriate Or .NET gives me some additional instrument to use
Sorry for the diozen of requests but I came from Java :)
If you mean validation against schema, validating XML reader is available on NETCF V2 and it works the same way as on desktop. There's no way to validate XML on NETCF V1 unless you do it all yourself.
If you copied it without any modifications (really you have to at least correct file paths), the output goes to console. Does your device have console If not, you won't see any output.
Yeah but to me it doesn't work. I tried this simple example: http://msdn2.microsoft.com/en-us/library/56xykaw6.aspx but it terminates correctly without raising any validation error. I copied the files without any modification but it doesn't work.
Someone has never tried to effective trying to validate an XML against a schema in CF Any suggestion
Xml validation
ofsarac
It does validate. I've just run the code from the sample on device (adjusted for paths and luck of console). Sure enough it shows expected message about attribute. Here’s my code (add two buttons and a textbox to the form, also add XML and XSD files to your project, set action to “Content” and condition to “Deploy always”):
using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Schema;
using System.IO;
using System.Reflection;
namespace ValidateXml
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
// Create and load the XML document.
XmlDocument doc = new XmlDocument();
doc.Load(Path.Combine(path, "booksSchema.xml"));
// Make changes to the document.
XmlElement book = (XmlElement) doc.DocumentElement.FirstChild;
book.SetAttribute("publisher", "Worldwide Publishing");
// Create an XmlNodeReader using the XML document.
XmlNodeReader nodeReader = new XmlNodeReader(doc);
// Set the validation settings on the XmlReaderSettings object.
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add("urn:bookstore-schema", Path.Combine(path, "books.xsd"));
settings.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack);
// Create a validating reader that wraps the XmlNodeReader object.
XmlReader reader = XmlReader.Create(nodeReader, settings);
// Parse the XML file.
while (reader.Read());
}
// Display any validation errors.
private void ValidationCallBack(object sender, ValidationEventArgs e)
{
this.textBox1.Text = String.Format("Validation Error: {0}", e.Message);
}
}
}
Radim Hampel
When I try to deploy it on the device it doesn't found the file but they are in the same folder...
Please help :)
Grettings
IGiberson
Sure. VS comes with a great help system which is accessible via F1 button. Just hit F1, type “File properties” and you’ll find them in no time.
Paul Stovell
velibicer
It could not possibly display any errors as PPC 2003 has no console. Change the code to pop up a message box or set a breakpoint in debugger.< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Device has no support for relative paths so putting files to the EXE folder won’t do you any good. Full path has to be specified or files won't be found.
One more thing: for some reasons many developers believe device can see desktop’s hard drive by simply specifying “C:\path\file”.
That is of course not the case – device can’t see desktop’s hard drive. So please make sure files are on device file system.
Job Lot
Latso
Ok another thing. This strategy to use XML for configuration of my app (Tomcat like) is the more appropriate Or .NET gives me some additional instrument to use
Sorry for the diozen of requests but I came from Java :)
Hi
ebeofrei
If you mean validation against schema, validating XML reader is available on NETCF V2 and it works the same way as on desktop. There's no way to validate XML on NETCF V1 unless you do it all yourself.
GregRoy
That's properties of files in VS project which are telling VS what to do with the file and when to do it. It's not device specific.
Cerw1n
If you copied it without any modifications (really you have to at least correct file paths), the output goes to console. Does your device have console If not, you won't see any output.
Jeon
Thanks for the tips :)
Hi
VladAll
Hi & thanks
Charley Lou
Thanks
Jonathan Sampson
Someone has never tried to effective trying to validate an XML against a schema in CF Any suggestion
Thank you