XmlDocument XmlDSig schema validation

Hi!
I must to validate xml document with XmlDSig and Xades Schema.
Why this code (with !obsolete! XmlValidatingReader) work and validate
xmldocument:

private bool schemaValidationStatus = true;
static void ValidationEventHandler(object sender, ValidationEventArgs
e)
{
	MessageBox.Show(e.Message);
    schemaValidationStatus = false;
}
public bool VerifySchemaVersionObsolete(string fileName)
{
    XmlTextReader xmlTextReader = new XmlTextReader(fileName);
    XmlValidatingReader xmlValidatingReader = new
XmlValidatingReader(xmlTextReader);
    xmlValidatingReader.ValidationType = ValidationType.Schema;
    xmlValidatingReader.Schemas.Add("http://www.w3.org/2000/09/
xmldsig#", "http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/
xmldsig-core-schema.xsd");
    xmlValidatingReader.Schemas.Add("http://uri.etsi.org/01903/
v1.3.2#", "http://uri.etsi.org/01903/v1.3.2/XAdES.xsd");
    xmlValidatingReader.ValidationEventHandler +=
ValidationEventHandler;
    while (xmlValidatingReader.Read())
    {
    }
	return schemaValidationStatus;
}

-- and this code (with .net 2.0 without !obsolete!
XmlValidatingReader) DONT WORK:

public bool VerifySchemaNet2(string fileName)
{
    XmlTextReader xmlTextReader = new XmlTextReader(fileName);
    XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
    xmlReaderSettings.ProhibitDtd = false;
    xmlReaderSettings.ValidationType = ValidationType.Schema;
    xmlReaderSettings.Schemas.Add("http://www.w3.org/2000/09/
xmldsig#", "http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/
xmldsig-core-schema.xsd");
    xmlReaderSettings.Schemas.Add("http://uri.etsi.org/01903/v1.3.2#",
"http://uri.etsi.org/01903/v1.3.2/XAdES.xsd");
    xmlReaderSettings.ValidationEventHandler +=
ValidationEventHandler;
    XmlReader xmlReader = XmlReader.Create(xmlTextReader,
xmlReaderSettings);
    while (xmlReader.Read())
    {
    }
	return schemaValidationStatus;
}

the error in code VerifySchemaNet2 is in line:
    readerSettings.Schemas.Add("http://www.w3.org/2000/09/xmldsig#",
"http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-
schema.xsd");
with message: to use DTD, set false to XmlReaderSettings.ProhibitDtd
and put this to XmlReader.Create method.
How can I validate xml document with
http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd
schema. I dont understand this, other schemas work good. Is imposible
do this with .net 2.0, I dont believe???
Has anybody the same problem?
Please for help!
Iguana
0
szewczykw (7)
12/7/2007 7:35:27 AM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
804 Views

Similar Articles

[PageSpeed] 56

It appears your .NET 2.0 code is correct, but I would check with the XSD 
files one by one whether they have a DTD 'call' or not.
ie, you will have to have a look in the XML code itself.
I think that if a particular XSD doesn't have a call to a DTD, setting
  xmlReaderSettings.ProhibitDtd = false;
means that it will expect a DTD, and doesn't find it. So, error.

Does that make sense?

-- 
Ian Thomas

"Iguana" <szewczykw@zetokatowice.pl> wrote in message 
news:ae5c9888-4d52-476d-88c8-4454f389d1b7@t1g2000pra.googlegroups.com...
> Hi!
> I must to validate xml document with XmlDSig and Xades Schema.
> Why this code (with !obsolete! XmlValidatingReader) work and validate
> xmldocument:
>
> private bool schemaValidationStatus = true;
> static void ValidationEventHandler(object sender, ValidationEventArgs
> e)
> {
> MessageBox.Show(e.Message);
>    schemaValidationStatus = false;
> }
> public bool VerifySchemaVersionObsolete(string fileName)
> {
>    XmlTextReader xmlTextReader = new XmlTextReader(fileName);
>    XmlValidatingReader xmlValidatingReader = new
> XmlValidatingReader(xmlTextReader);
>    xmlValidatingReader.ValidationType = ValidationType.Schema;
>    xmlValidatingReader.Schemas.Add("http://www.w3.org/2000/09/
> xmldsig#", "http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/
> xmldsig-core-schema.xsd");
>    xmlValidatingReader.Schemas.Add("http://uri.etsi.org/01903/
> v1.3.2#", "http://uri.etsi.org/01903/v1.3.2/XAdES.xsd");
>    xmlValidatingReader.ValidationEventHandler +=
> ValidationEventHandler;
>    while (xmlValidatingReader.Read())
>    {
>    }
> return schemaValidationStatus;
> }
>
> -- and this code (with .net 2.0 without !obsolete!
> XmlValidatingReader) DONT WORK:
>
> public bool VerifySchemaNet2(string fileName)
> {
>    XmlTextReader xmlTextReader = new XmlTextReader(fileName);
>    XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
>    xmlReaderSettings.ProhibitDtd = false;
>    xmlReaderSettings.ValidationType = ValidationType.Schema;
>    xmlReaderSettings.Schemas.Add("http://www.w3.org/2000/09/
> xmldsig#", "http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/
> xmldsig-core-schema.xsd");
>    xmlReaderSettings.Schemas.Add("http://uri.etsi.org/01903/v1.3.2#",
> "http://uri.etsi.org/01903/v1.3.2/XAdES.xsd");
>    xmlReaderSettings.ValidationEventHandler +=
> ValidationEventHandler;
>    XmlReader xmlReader = XmlReader.Create(xmlTextReader,
> xmlReaderSettings);
>    while (xmlReader.Read())
>    {
>    }
> return schemaValidationStatus;
> }
>
> the error in code VerifySchemaNet2 is in line:
>    readerSettings.Schemas.Add("http://www.w3.org/2000/09/xmldsig#",
> "http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-
> schema.xsd");
> with message: to use DTD, set false to XmlReaderSettings.ProhibitDtd
> and put this to XmlReader.Create method.
> How can I validate xml document with
> http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd
> schema. I dont understand this, other schemas work good. Is imposible
> do this with .net 2.0, I dont believe???
> Has anybody the same problem?
> Please for help!
> Iguana 


0
gxdata (17)
1/25/2008 6:34:03 AM
Reply:

Similar Artilces:

XMLWriter and XMLDocument
Okay I am using an XMLDocument object to process several thousands of lodgements (from a database) I am trying to output it from an XML Document to a file using the XmlDocument.WriteTo() method with an XmlWriter. It writes 131kB and then cuts out halfway through an element Is this a limitation of XmlDocument.WriteTo() ? What would be a better way to output it Thanks Ensure you're calling XmlWriter.Close() to cause the buffered writes to be flushed to the underlying stream/textwriter. -- Daniel Cazzulino [MVP XML] Clarius Consulting SA http://weblogs.asp.net/cazzu http://aspnet2.com ...

Pivot tabel field name not valid in 2007, was in 2003
I have a workbook created in 2003. When I refresh pivot tables within in 2003, all is fine. When I open in 2007 and refresh, I get the "pivot table field name not valid" error. There are no problems with columns missing headers. I can solve it by changing the data source, but I've got thousands of pivot tables to update. ...

Validation in excel
Hi, I am have been dumped with some work that is beyond my knowledge and would wecome any help. I want to use validation to not allow data entry if another cell is blank. I have various routes but no joy. This will be the first of many questions I feel. Hope to hear from you soon. Regards Rugby Man Just use Data Validation with a custom type, and a formula of say =C1<>"" Uncheck the Ignore blank box. -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Rugby Man" <paul.senior@bt.com> wrote in message news:11...

how to include schema declaration in xslt output
I apologize if this has been answered before, I couldn't find it. I'm trying to transform XML to XML and specify a schema in the output XML. I am transforming nodes to different local names while keeping the same namespace. This works fine, until I try to introduce the schema. My input looks like this: <a xmlns="some_url"> <b>doo dah</b> </a> I want this output: <x:c xmlns:x="some_url" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" xsi:schemaLocation="some_url myschema.xsd"> <x:d>doo dah<...

XmlDocument with URL
My goal is to load an xml document from a remote url, make some changes to it, and then display it in a webpage. Say my codebehind looks like this private void Page_Load(Object sender, EventArgs e) { XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8); XmlDocument doc = new XmlDocument(); doc.Load(http://somexmlgeneratedhere.com?id=333); //manipulate the doc here doc.WriteTo(writer); } Im not getting the full document from the URL, I'm sure Im doing this wrong. Can anyone point me in the right direction? thanks in advance Dave He...

Why can't I make changes to the activity schema?
I'd like to add some fields and change the pick lists for the activity object. Is that possible? Ed, I'm sure it can be done. I have yet to be successful at it though. The way Activities were designed, they aren't as flexible. All te forms are actually hard coded ASPX pages vs the rest of the system which uses XML & XSLT to generate the displayed forms. CRM 2005 promises this capability though. Matt Parks MVP - Microsoft CRM ---------------------------------------- ---------------------------------------- On Sat, 21 Aug 2004 22:17:01 -0700, "Ed Hargrave" <E...

Boolean values in schemas
Hi. I want to to use the xs:boolean type for one of my elements. But is it possible to make these boolean values be read as Yes/No instead of true/false? Should I create a custom type for that? Thank you. Julian According to the XMLSchema datatypes spec, the following are the allowed values for xs:boolean 3.2.2.1 Lexical representation An instance of a datatype that is defined as ´┐Żboolean´┐Ż can have the following legal literals {true, false, 1, 0}. If you need the values to be Yes/No it has to be a custom type derived from xs:string with enumerations "Yes" and "No" ...

Outlook 2007 list of valid TZIDs?
Hello, I'm trying to write a web app that exports .ics files for users to import into calendar applications. When I try to import my .ics file into Outlook, I get a warning / error message telling me that Outlook does not like the TZID: "The VEVENT, "xxx", defined near line 14, contains a property that references an undeclared time zone with a TZID of "Australia/Sydney". Outlook found an approximate replacement, but note that some of your appointments may be off by an hour. Double-click to open this item." I'm trying to find a list of...

Internal problem on XmlDocument.Load( )
I have this really frustrating problem when calling XmlDocument.Load(string filename). Whenever I call this method in a web application in my Windows XP development PC, I get the following error: Specified argument was out of the range of valid values. Parameter name: The specified value must be greater than 0. Here's the stack trace: ------------------------- [ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: The specified value must be greater than 0.] System.Net.ServicePoint.set_ConnectionLimit(Int32 value) +60 System.Xml.XmlDo...

Find records that do not conform to schema
We have an application right now that determines if an XML document sent in conforms to schema. What we have now been asked to do is add functionality that creates an exception report for all records that do not conform to our schema (XSD). One of the team members has built some functionality that loops through the records, node by node, and determines which nodes do not conform, but it is taking way too long to develop. Does anyone know a quicker way to develop this with the .NET XML classes? We are at brainstorming stage, so any ideas are potential winners. -- Gregory A. Beamer MV...

Cell Validation #2
Hi, My cell validation does not appear to be working when the calculate takes time. My sheet can take upto 30 seconds to calculate, but when I type a value into a validated cell, I am not getting a message that the the entry is invalid... I have removed the validation and re-set it up... no luck... thoughts? Simon Never heard of this. It sounds as if you have calculate set to Automatic. I don't suppose setting it to Manual helps? -- Jim Rech Excel MVP "Simon Shaw" <SimonShaw@discussions.microsoft.com> wrote in message news:7D5E5668-4BDA-4891-BB3F-37173CE23DB7@m...

Xml validation exception only occurs outside debugger
Hi, I am experiencing a strange problem. I am reading and writing xml files via XmlDocument and XmlTextWriter. In the debugger everything works fine but outside the debugger (debug or release) I receive the following error: "The type initializer for "System.Xml.Schema.Validator" threw an exception." I wrote a small console app that contains the problem -- I've just attached the default class which gets run. Output outside the debugger is as follows ------------------ Creating xml file Reading xml file Error reading xml file The type initializer for "Syst...

Validation of numbers
hey I want to validate a cell so that it will only accept numbers, no text. These numbers could be decimals or whole numbers, therefore th Whole number option won't work. I tried the Decimal option, but i still allowed text. Can u help?? Thx KrisB_baco -- Message posted from http://www.ExcelForum.com One way (assume A1 is the cell) =ISNUMBER(A1) -- Regards, Peo Sjoblom "KrisB_bacon >" <<KrisB_bacon.11vmuj@excelforum-nospam.com> wrote in message news:KrisB_bacon.11vmuj@excelforum-nospam.com... > hey > > I want to validate a cell so that it will ...

Data validation screen size
Step one - from the menu I selected data validation Determined the settings for the data validation Determined the title and the input message Did not like the format of the input message - when the cursor is on the cell that was just work on. Therefore my question is: Can one control the size of the pop-up window (length and height) created by using data validation input message? You can't control the size of the data validation input message. If you can use programming, you could use a textbox to display the input message. There's an example here: http://www.contextu...

(beginner)validating an xml doc with vb.net
Dear Users, I'm programming a vb.net client; I have to provide a new feature that has to validates an xml document with an existing dtd file (or a schema) associated with the xml document. Anyone knows how can I do it ? Is there any kind of method or instructions that match with my problem ? Any suggest will be kindly appreciated. Best regards. Fabrizio ...

SchemaSet.Compile()
I have a very complex XSD with lots of imports and schemaRefs. <longshot>I'm cheating and want to be able use the XSD.exe tool to simplify serialization soooooooo was wondering if there's a possibility of compiling the schema into a single logical set and then writing it out as a single XSD.</longshot> any pointers graciously accepted. Allen Allen wrote: > I have a very complex XSD with lots of imports and schemaRefs. > > <longshot>I'm cheating and want to be able use the XSD.exe tool to simplify > serialization soooooooo was wondering if ...

Define range for graphs/charts with validation list
Hi I would like to change the range for a graph with a dropdown list See attached picture to get the feeling. I don't want to have 12 chart for each month, but one graph and a validation dropdown list with whic I can dictate the graphs' data ranges. If I select January in the dropdown list, I must take the january rang for the graph, etc. I do not know if this is possible, but if it is possible that would b an awesome solution +------------------------------------------------------------------- |Filename: example.jpg |Download: http://www...

XSLT transform XmlDocument to XmlDocument?
I just want to make a transformation on the fly, without having to save the XML document to a file before or after the transformation. I don't find any examples of this. I see that the XslTranform.Transform() method can return an XmlReader, but how can that reader be converted to an XmlDocument object? Big thanks, Gustaf Gustaf Liljegren wrote: > I just want to make a transformation on the fly, without having to save > the XML document to a file before or after the transformation. I don't > find any examples of this. See <http://groups-beta.google.com/group/mic...

validating XML using XmlValidatingReader
I am having some trouble validating XML using the XmlValidatingReader. I have created some xml and used the visual studio to generate the schema. So I am confident that the xml and schema match. The problem I am having is that the validation event fires for each node in the xml. It seems to be completely ignoring the schema that I have used. I'm wondering if I need to do something extra to tell the xml which schema to use. Here's the code. Any help at all would be great. Thanks Andy public sub Main() Dim sSchema As String = "<?xml version='1.0'?>...

Schema design
I have a schema change we are debating here and I wonder what the MVP's might think about this. We need to add a flag to a record that will be used to trigger certain events. The parent table is the ChangeCodes table. Each Change Code has a Change Type that tells our external interfaces what to do with the record. The rules in the type record are for communicating with a specific interface, the new flag will be used for a different interface. The type flags are all hiden from the end user, the name of the type is controlled by the DBA and is descriptive enough to help t...

XmlNode -> Schema -> Object
Lets say I have an XmlNode that validates against some schema. I also have a class that was generated by the xsd tool using said schema. What is the best way to get from an XmlNode to an instance of the class? System.Xml.Serialization.XmlSerializer.Deserialize() accepts an XmlReader. http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemXmlSerializationXmlSerializerClassDeserializeTopic3.asp and you can create a System.Xml.XmlNodeReader from a System.Xml.XmlNode http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemXmlXmlNodeReaderClassctorTopic.asp "Brad Quinn&quo...

XPathDocument to xmldocument
How to create XPathDocument object from xmldocument object thanks vikram wrote: > How to create XPathDocument object from xmldocument object First, be aware that such converting means copying the whole set of data in the XML document. Second, it's easy: XPathDocument doc = new XPathDocument(new XmlNodeReader(xmlDoc)); -- Oleg Tkachenko [XML MVP, MCP] http://blog.tkachenko.com ...

Loading XmlDocument with a file on network?
Can you load an XmlDocument with a file located on a network share? I thought maybe the XmlResolver could be used XmlUrlResolver resolver = new XmlUrlResolver() resolver.Credentials = CredentialCache.DefaultCredentials // Create and load the XmlDocument XmlDocument doc = new XmlDocument() doc.XmlResolver = resolver; // Set the resolver doc.Load(@"\\devsrv\profiles\0004.xml") OR.. doc.Load("//devsrv/profiles/0004.xml") But I get: "Logon failure: unknown user name or bad password" The problem is probably that the account that your application is running under...

data validation #18
hi i have a worksheet (template) that has cell contain data validation(i.e drop down list) problem is when i run a macro that saves the information to another worksheet(output) it is killing the data validation on the worksheet(template). Can anyone suggest a reason why macros kill data validation and how i can fix it? thanks in advance kevin Do you actually have a template file open (*.xlt), or is this a copy of a template file, or a normal workbook? If you select a cell with data validation, and choose Data>Validation, can you see the validation criteria that were previously set...

removing nodes from xmldocument
Here is an xml structure. i want to remove <a> nodes that do not have any child. How can i do that in csharp? <root> <a> <b/> </a> <a/> <a/> <a> <c/> </a> </root> i tried following but it does not work: xmlNodeList l = xr.getElementsByTagName("a"); foreach(XmlNode n in l) { if(n.HasChildNodes == false) xr.RemoveChild(n) } emid, Try this call this function inside the code; void RecurssionRemoval() { XmlNodeList l = xr.GetElementsByTagName("a"); ...