473,473 Members | 1,511 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XML Document with BASE64 Encoded Sections

I have an xml document that contains some elements encoded as Base64. How do
I dynamically scan the XML Document and pull out the sections that are
Base64...

My overall goal is to display the XML document in a browser will all the
Base64 sections converted to Ascii (UTF-8).
Nov 17 '05 #1
6 8743


Chris Fink wrote:
I have an xml document that contains some elements encoded as Base64.
What does that mean, there are elements that have contents that is
Base64 encoded?
Or what are "elements encoded as Base64"?
How do
I dynamically scan the XML Document and pull out the sections that are
Base64...


Is there some indication in the document or in a schema for the document
that an element has base64 encoded contents e.g. an attribute indicating
the type perhaps
<data xsi:type="xs:base64Binary">...</data>

Or do you know the tag names of the elements containing base64 encoded data?

You could access the InnerText of such an element and use the method
Convert.FromBase64String
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemConvertClassFromBase64StringTopic.asp>
to convert the text content to a byte array.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 17 '05 #2
Yes, the XML document does indicate which elemets are Base64 encoded as such:
<xsd:element name="Payload" type="xsd:base64Binary"/>

I do know the tag names now, but would like to make it more flexible since
additional tag names in the future may be added that would break the design.

My main challenge is to dynamically find the elements that are Base64 and
decode them to Ascii (UTF-8). I just need help on finding these sections.
"Martin Honnen" wrote:


Chris Fink wrote:
I have an xml document that contains some elements encoded as Base64.


What does that mean, there are elements that have contents that is
Base64 encoded?
Or what are "elements encoded as Base64"?
How do
I dynamically scan the XML Document and pull out the sections that are
Base64...


Is there some indication in the document or in a schema for the document
that an element has base64 encoded contents e.g. an attribute indicating
the type perhaps
<data xsi:type="xs:base64Binary">...</data>

Or do you know the tag names of the elements containing base64 encoded data?

You could access the InnerText of such an element and use the method
Convert.FromBase64String
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemConvertClassFromBase64StringTopic.asp>
to convert the text content to a byte array.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Nov 17 '05 #3


Chris Fink wrote:
Yes, the XML document does indicate which elemets are Base64 encoded as such:
<xsd:element name="Payload" type="xsd:base64Binary"/>
That looks like a schema definition. A schema is usually external to the
XML instance document e.g. your XML instance document is then more
likely to have
<PayLoad>base64 encoded data sits here</PayLoad>
I just need help on finding these sections.


There are various APIs in the .NET framework to read out information
from an XML document, there is XmlTextReader which is a fast forward
only pull parsing approach that does not consume much memory but
requires you to set up your own code to extract data and store it.
There is XPathDocument which loads a complete document in memory into an
optimized data structure for read only XPath navigation and data access.
And there is XmlDocument which also loads the complete document in
memory but in a structure which allows manipulation. XmlDocument also
allows XPath navigation.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 17 '05 #4
Martin,

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. Your suggestions?

"Martin Honnen" wrote:


Chris Fink wrote:
Yes, the XML document does indicate which elemets are Base64 encoded as such:
<xsd:element name="Payload" type="xsd:base64Binary"/>


That looks like a schema definition. A schema is usually external to the
XML instance document e.g. your XML instance document is then more
likely to have
<PayLoad>base64 encoded data sits here</PayLoad>
I just need help on finding these sections.


There are various APIs in the .NET framework to read out information
from an XML document, there is XmlTextReader which is a fast forward
only pull parsing approach that does not consume much memory but
requires you to set up your own code to extract data and store it.
There is XPathDocument which loads a complete document in memory into an
optimized data structure for read only XPath navigation and data access.
And there is XmlDocument which also loads the complete document in
memory but in a structure which allows manipulation. XmlDocument also
allows XPath navigation.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Nov 17 '05 #5


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/
Nov 17 '05 #6
Exactly what I was looking for.

Thank you very much!

"Martin Honnen" wrote:


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/

Nov 17 '05 #7

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

Similar topics

3
by: Michael | last post by:
I am trying to integrate my ASP page with an external application that sends me a QueryString that is URLEncoded and each Name and Value in the QueryString is Base64 Encoded as well. ...
4
by: John | last post by:
Hi all, I've been going through google and yahoo looking for a certain base64 decoder in C without success. What I'm after is something that you can pass a base64 encoded string into and get back...
2
by: kevin | last post by:
DISCLAIMER: I know what the words mean (i.e. by definition), but I in know way pretend to understand the specifics of either, therefore I may need a basic primer before I can accomplish this task,...
0
by: Phil C. | last post by:
(Cross post from framework.aspnet.security) Hi. I testing some asp.net code that generates a 256 bit Aes Symmetric Key and a 256 bit entropy value. I encrypt the Aes key(without storing it as...
7
by: Neo Geshel | last post by:
Greetings. I have managed to stitch together an awesome method of posting text along with an image to a database, in a way that allows an unlimited number of previews to ensure that text and...
14
by: BB | last post by:
Hello. i am trying to decode a block of (what i think is) base64 into text, and i have NO idea how to begin. I'm going to paste the whole string here, but i want to know the steps necessary to...
1
by: mirandacascade | last post by:
I am attempting to implement a process, and I'm pretty sure that a major roadblock is that I do not understand the nomenclature. The specs indicate that the goal is to calculate a message digest...
13
by: aruna.eies.eng | last post by:
i am currently trying to convert data into binary data.for that i need to know how to achieve it in c language and what are the libraries that we can use. so if any one can send me a sample code or...
4
by: Sam | last post by:
Hi, I am using some functions return a base64 encoded string. The functions write it into an unsigned char buffer. I am a little confused as to why a base64 encoded string would be using an...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.