Re: XML Document with BASE64 Encoded Sections

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance





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/
.



Relevant Pages

  • Re: how to return xml document from a web service
    ... what specific XML you expect. ... If you have a schema that defines what you expect, ... The second issue with this approach is that XML is not a string. ... >> methods from the wire transport. ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • my first Tck/Tk program... and an XML question
    ... program which takes an XML Schema file, ... a basic XML tree and allows the user to save it. ... proc open_schema { ...
    (comp.lang.tcl)
  • RE: Data Insertion
    ... >The physical database structure is already in place. ... >I can determine the XML file and whether it contains a schema. ... In this particular case XML Schema is used to create a DataSet schema (set ... you're probably wondering how it's possible to load XML without XML ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Interplatform (interprocess, interlanguage) communication
    ... complain that XML isn't sufficiently flexible. ... starts encoding nodes which lie outside the schema). ... format: it can build the functional analogue of a schema as it encodes ... XML would be just fine as a transmission protocol for such a thing. ...
    (comp.lang.java.programmer)
  • Re: Interplatform (interprocess, interlanguage) communication
    ... complain that XML isn't sufficiently flexible. ... have a format which is at the same time is a compressed binary format, and can also retain the full flexibility of representing free-form XML semantics, ideally without a major drop in compactness (this happens with WBXML, and IIRC should also happen with EXI about as soon as one starts encoding nodes which lie outside the schema). ...
    (comp.lang.java.programmer)