Re: XML Document with BASE64 Encoded Sections
- From: Martin Honnen <mahotrash@xxxxxxxx>
- Date: Thu, 20 Oct 2005 17:28:22 +0200
Chris Fink wrote:
So without the xml fragment containing an attribute that describes it's type, I cannot dynamically determine the sections that are base64? I was thinking that the definition of the type in the schema would be sufficient? The XML doc contains a reference to the schema, so I would think the solution would be to scan the xsd for base64 types and then pull out these sections from the xml fragment and convert to ascii.
If the schema and the instance are available then you can use an XmlValidatingReader and access type informations from the schema while parsing the XML instance document. The following snippet checks for elements with bas64Binary typed contents and reads out the content into a byte array then:
XmlValidatingReader validator = new XmlValidatingReader(new XmlTextReader(@"test2005102001.xml"));
validator.ValidationType = ValidationType.Schema;
validator.ValidationEventHandler += new ValidationEventHandler(ValidationHandler);
while (validator.Read()) {
if (validator.NodeType == XmlNodeType.Element) {
if (validator.SchemaType is XmlSchemaDatatype) {
XmlSchemaDatatype currentType = (XmlSchemaDatatype)validator.SchemaType;
if (currentType.ToString() == "System.Xml.Schema.Datatype_base64Binary") {
Console.WriteLine("Element {0} has base64Binary type.", validator.Name);
object currentValue = validator.ReadTypedValue();
Console.WriteLine("Typed value read as {0}.", currentValue.GetType().Name);
// could use currentValue as byte[] here
}
}
}
}
validator.Close();
--
Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ .
- Follow-Ups:
- Re: XML Document with BASE64 Encoded Sections
- From: Chris Fink
- Re: XML Document with BASE64 Encoded Sections
- References:
- Re: XML Document with BASE64 Encoded Sections
- From: Martin Honnen
- Re: XML Document with BASE64 Encoded Sections
- From: Martin Honnen
- Re: XML Document with BASE64 Encoded Sections
- Prev by Date: Re: AttributeNodeSuggestion?
- Next by Date: Timezone and time API problem (.net bug!?)
- Previous by thread: Re: XML Document with BASE64 Encoded Sections
- Next by thread: Re: XML Document with BASE64 Encoded Sections
- Index(es):
Relevant Pages
|