472,972 Members | 2,206 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,972 software developers and data experts.

Retain default attribute values after XSD Validation?

In my app I'm validating an XML file against an XSD which contains several
attribute default value specifications. I'm performing the validation via an
xml document load() using a ValidatingXMLReader. After loading the document
(and validating it) I assume that the resulting doc will (as appropriate)
have elements with attributes set to their default values in those cases
where there was nothing specified in the input XML file.

However, when I serialize the resulting doc using its WriteContentTo method,
the default attributes are NOT represented in the XML output stream. Is this
expected behaviour and, if so, how can I arrange to retain these default
attribute values?

Thanks in advance,
Bill
Nov 12 '05 #1
2 3913
"Bill Cohagan" <bi**@teraXNOSPAMXquest.com> wrote in message news:uT**************@TK2MSFTNGP11.phx.gbl...
In my app I'm validating an XML file against an XSD which contains several
attribute default value specifications. : : when I serialize the resulting doc using its WriteContentTo method,
the default attributes are NOT represented in the XML output stream. Is this
expected behaviour and, if so, how can I arrange to retain these default
attribute values?


WriteContentTo( ) could have any of three motivations:

1.) It could generate an XML serialization preserving as much of the
original XML serialization as possible, including insignificant white
space and the quote characters delimiting each attribute value.

(I'd dismiss this as it imposes too heavy of a burden to maintain
knowledge of the original serialization format. The XML Infoset
is unconcerned with these minutia which it sees as irrelevant
artifacts of the serialization. XmlDocument is a model of the
Infoset.)

2.) It could generate XML that is canonically equivalent to the
original serialization format. This disregards irrelevant minutia,
such as the quantity of whitespace between attributes in an
element tag. It preserves those details of importance when
two XML documents must be compared for equivalence; which
has important applications in XML Encryption and XML Digital
Signatures.

3.) It could produce the Post Schema Validation Infoset (or PSVI),
if available. The PSVI contains value-added information from the
schema validation process, such as default attribute values, that
were not present in the original document. While additive, this
creates a document which is not equivalent to the original source,
and under some circumstances might be undesirable.

As one example of where producing the PSVI could be a mistake,
suppose I have an XML document with a child element, Account.
Account may have an attribute, MaxFDICInsuredBalance, defined
in the XML Schema as having the default value of $100,000.00.
Being a bank, I'll want to digitally sign the Account element to both
preserve its integrity (detect any alteration) and authenticate myself
(or my back-end process) as being the last person to modify it.

What happens if I schema-validate this digitally-signed document
in a ValidatingXmlReader and then pass it along to another process
that verifies the authenticity of the digital signature? 'Lo and behold,
should WriteContentTo( ) produce a serialization based on the PSVI
rather than one thats canonically equivalent to the original signed
document, the Account element has been tampered with!

Looking at it more closely, the explicit content of the Account element
would've changed were a WriteContentTo( ) to serialize the PSVI.
It would now contain the implied attribute value of $100,000.00 for
MaxFDICInsuredBalance, whereas the Account element was signed
when that wasn't present.

If WriteContentTo( ) did intend to serialize the document in a canonically
equivalent representation of its original content (rather than the serialize
the document's PSVI including default attribute nodes), I imagine it would
employ the IsDefault property of XmlReader to do so.

This nugget may suggest an answer to your second question, how to retain
the default attribute values?

Try subclassing ValidatingXmlReader and override the virtual IsDefault
property to always return false.

- - - KeepPsviDefAttrs.cs
using System.Xml;
public class MyValidatingXmlReader : ValidatingXmlReader {
public override bool IsDefault { get { return false; } }
}
- - -

Then use this MyValidatingXmlReader when loading the XmlDocument.
Whenever WriteContentTo( ) asks whether a given attribute node should
be serialized because it was added as a default value, you can direct
WriteContentTo( ) to ignore this distinction (serialize all attributes whether
they are default or not).
HTH,

Derek Harmon
Nov 12 '05 #2
Derek
Good summary of the problem -- and good solution as well. Overriding the
isDefault method solves the problem.

Thanks again!

Bill

"Derek Harmon" <lo*******@msn.com> wrote in message
news:uA****************@tk2msftngp13.phx.gbl...
"Bill Cohagan" <bi**@teraXNOSPAMXquest.com> wrote in message news:uT**************@TK2MSFTNGP11.phx.gbl...
In my app I'm validating an XML file against an XSD which contains several attribute default value specifications.

: :
when I serialize the resulting doc using its WriteContentTo method,
the default attributes are NOT represented in the XML output stream. Is this expected behaviour and, if so, how can I arrange to retain these default
attribute values?


WriteContentTo( ) could have any of three motivations:

1.) It could generate an XML serialization preserving as much of the
original XML serialization as possible, including insignificant white
space and the quote characters delimiting each attribute value.

(I'd dismiss this as it imposes too heavy of a burden to maintain
knowledge of the original serialization format. The XML Infoset
is unconcerned with these minutia which it sees as irrelevant
artifacts of the serialization. XmlDocument is a model of the
Infoset.)

2.) It could generate XML that is canonically equivalent to the
original serialization format. This disregards irrelevant minutia,
such as the quantity of whitespace between attributes in an
element tag. It preserves those details of importance when
two XML documents must be compared for equivalence; which
has important applications in XML Encryption and XML Digital
Signatures.

3.) It could produce the Post Schema Validation Infoset (or PSVI),
if available. The PSVI contains value-added information from the
schema validation process, such as default attribute values, that
were not present in the original document. While additive, this
creates a document which is not equivalent to the original source,
and under some circumstances might be undesirable.

As one example of where producing the PSVI could be a mistake,
suppose I have an XML document with a child element, Account.
Account may have an attribute, MaxFDICInsuredBalance, defined
in the XML Schema as having the default value of $100,000.00.
Being a bank, I'll want to digitally sign the Account element to both
preserve its integrity (detect any alteration) and authenticate myself
(or my back-end process) as being the last person to modify it.

What happens if I schema-validate this digitally-signed document
in a ValidatingXmlReader and then pass it along to another process
that verifies the authenticity of the digital signature? 'Lo and behold,
should WriteContentTo( ) produce a serialization based on the PSVI
rather than one thats canonically equivalent to the original signed
document, the Account element has been tampered with!

Looking at it more closely, the explicit content of the Account element
would've changed were a WriteContentTo( ) to serialize the PSVI.
It would now contain the implied attribute value of $100,000.00 for
MaxFDICInsuredBalance, whereas the Account element was signed
when that wasn't present.

If WriteContentTo( ) did intend to serialize the document in a canonically
equivalent representation of its original content (rather than the

serialize the document's PSVI including default attribute nodes), I imagine it would
employ the IsDefault property of XmlReader to do so.

This nugget may suggest an answer to your second question, how to retain
the default attribute values?

Try subclassing ValidatingXmlReader and override the virtual IsDefault
property to always return false.

- - - KeepPsviDefAttrs.cs
using System.Xml;
public class MyValidatingXmlReader : ValidatingXmlReader {
public override bool IsDefault { get { return false; } }
}
- - -

Then use this MyValidatingXmlReader when loading the XmlDocument.
Whenever WriteContentTo( ) asks whether a given attribute node should
be serialized because it was added as a default value, you can direct
WriteContentTo( ) to ignore this distinction (serialize all attributes whether they are default or not).
HTH,

Derek Harmon

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark R | last post by:
I have one .asp page with a SELECT pulldown list on it and some INPUT fields. When SUBMIT is clicked the form data is submitted to that same page and validated. If INPUT fields are empty the asp...
4
by: blu4899 | last post by:
Hi, The Xerces XML parser is reading external DTD references in DOCTYPEs by default, but is not doing anything with them because validation is turned off by default. This is documented in...
1
by: UndoMiel | last post by:
Hi, I have a situation where i would like to validate the occurance of certain elements, based on the value of an attribute. What is the "best" way to handle such validations? I am fairly new...
4
by: Lénaïc Huard | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, I've some namespace problems when defining default values for attributes. My problem seems to come from the fact that the attributes are...
12
by: Stefano | last post by:
Hi all, what is the correct use of the "default" attribute in XML Schema? For example: <xs:element name="myProperty" type="xs:string" default="myDefaultValue"/> What can I do with it? What...
44
by: gregory.petrosyan | last post by:
Hello everybody! I have little problem: class A: def __init__(self, n): self.data = n def f(self, x = ????) print x All I want is to make self.data the default argument for self.f(). (I
3
by: Gary Wessle | last post by:
Hi the second argument in the functions below suppose to retain its value between function calls, the first does, the second does not and I would like to know why it doesn't? and how to make it...
1
by: Harinath | last post by:
Hi All, I am working on a portal using .net2.0. In one of my page, i have FileUpload control. I am doing some server side validation for form fields in general. if there is any validation...
2
by: Radu | last post by:
Hi. I have been working at home on a web project (VSNET 2005 SP1). Now I have brought the project at work, and I suddenly have plenty of warnings like: Validation (XHTML 1.0 Transitional) -...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.