473,609 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question on xPath iterator and Base64 encoding

Hi all,
please pardon me if this question is too trivial. I have an XML file
which stores data in base64. The schema is something like this,
<Remokon>
<Brand Name="SONY">
<Model Name="Type 1", Freq="2">
<Key ID="1" Len="42">
YR0RHhEOEQ0RHiE NEg0RDhIMEg0hHR INEgwSDSIcEg0SD BINEg0R/4QA
</Key>
<Key ID="2" Len="38">
YhwSHRIMEg0yLBI MEwwSDRIMIhwTDB INEgwiHCINEhwSD RL/hAA=
</Key>
.....
</Model>
<Model Name="Type 2">
....
</Model>
</Brand>
<Brand Name="Philips>
....
</Brand>
....
</Remokon>

The value of the Key node stores binary data encoded using base64. I can
use .NET's XmlWriter and XmlReader to read and write with no issue. I
use a byte array to receive the decoded binary data, length is specified
by the len attribute of the key note.

As can be see, this seves as some kind of database which I would like to
query using XPath. Herein lies the question, how do I read the value o
fthe key node when I query for all the keys in a Brand's Model? My xpath
query is correct as I tried using string as the value adn it was able to
obtain the keys correctly. the query is something like SELECT all keys
where Brand="SONY" and Model="Type 1". Can someone please enlighten me
on how to use xpath's iterator to retrieve the value stored in Base64
encoded data and decode back into binary data based on the Len attribute
of the Key? I saw the iterator's Current.Value retrieves a string,
ValueAsLong, etc, but sadly no ValueAsBase64. XmlReader has a
ReadAsBase64 function which i used for reading the entire file. But
surely i won't want to use a SELECT * FROM * kind of query on a
database. Please can somebody enlighten me on this? Thank you so much
for your kind assistance on my query.
Aug 12 '06 #1
2 4664


Lonewolf wrote:

please pardon me if this question is too trivial. I have an XML file
which stores data in base64. The schema is something like this,
<Remokon>
<Brand Name="SONY">
<Model Name="Type 1", Freq="2">
<Key ID="1" Len="42">
YR0RHhEOEQ0RHiE NEg0RDhIMEg0hHR INEgwSDSIcEg0SD BINEg0R/4QA
</Key>
<Key ID="2" Len="38">
YhwSHRIMEg0yLBI MEwwSDRIMIhwTDB INEgwiHCINEhwSD RL/hAA=
</Key>
....
</Model>
<Model Name="Type 2">
...
</Model>
</Brand>
<Brand Name="Philips>
...
</Brand>
...
</Remokon>

The value of the Key node stores binary data encoded using base64. I can
use .NET's XmlWriter and XmlReader to read and write with no issue. I
use a byte array to receive the decoded binary data, length is specified
by the len attribute of the key note.

As can be see, this seves as some kind of database which I would like to
query using XPath. Herein lies the question, how do I read the value o
fthe key node when I query for all the keys in a Brand's Model? My xpath
query is correct as I tried using string as the value adn it was able to
obtain the keys correctly. the query is something like SELECT all keys
where Brand="SONY" and Model="Type 1".
Here is a .NET 2.0/C# example that uses the Select method with an
appropriate XPath expression to get a node iterator over the Key
elements, then uses ReadSubtree to get an XmlReader and then applies
ReadElementCont entAsBase64:

XPathDocument xPathDocument = new XPathDocument(@ "file.xml") ;
XPathNavigator navigator = xPathDocument.C reateNavigator( );
XPathNodeIterat or nodeIterator = navigator.Selec t(
"/Remokon/Brand[@Name = 'SONY']/Model[@Name = 'Type 1']/Key");
while (nodeIterator.M oveNext()) {
using (XmlReader xmlReader = nodeIterator.Cu rrent.ReadSubtr ee()) {
if (xmlReader.Read ()) {
byte[] buffer = new byte[2048];
try {
int bytesRead =
xmlReader.ReadE lementContentAs Base64(buffer, 0, buffer.Length);
Console.WriteLi ne("Read {0} bytes.", bytesRead);
}
catch (Exception e) {
Console.WriteLi ne("Error {0} reading key.", e);
}
}
}
}

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Aug 12 '06 #2
Martin Honnen wrote:
>

Lonewolf wrote:

> please pardon me if this question is too trivial. I have an XML
file which stores data in base64. The schema is something like this,
<Remokon>
<Brand Name="SONY">
<Model Name="Type 1", Freq="2">
<Key ID="1" Len="42">
YR0RHhEOEQ0RHi ENEg0RDhIMEg0hH RINEgwSDSIcEg0S DBINEg0R/4QA
</Key>
<Key ID="2" Len="38">
YhwSHRIMEg0yLB IMEwwSDRIMIhwTD BINEgwiHCINEhwS DRL/hAA=
</Key>
....
</Model>
<Model Name="Type 2">
...
</Model>
</Brand>
<Brand Name="Philips>
...
</Brand>
...
</Remokon>

The value of the Key node stores binary data encoded using base64. I
can use .NET's XmlWriter and XmlReader to read and write with no
issue. I use a byte array to receive the decoded binary data, length
is specified by the len attribute of the key note.

As can be see, this seves as some kind of database which I would like
to query using XPath. Herein lies the question, how do I read the
value o fthe key node when I query for all the keys in a Brand's
Model? My xpath query is correct as I tried using string as the value
adn it was able to obtain the keys correctly. the query is something
like SELECT all keys where Brand="SONY" and Model="Type 1".

Here is a .NET 2.0/C# example that uses the Select method with an
appropriate XPath expression to get a node iterator over the Key
elements, then uses ReadSubtree to get an XmlReader and then applies
ReadElementCont entAsBase64:

XPathDocument xPathDocument = new XPathDocument(@ "file.xml") ;
XPathNavigator navigator = xPathDocument.C reateNavigator( );
XPathNodeIterat or nodeIterator = navigator.Selec t(
"/Remokon/Brand[@Name = 'SONY']/Model[@Name = 'Type 1']/Key");
while (nodeIterator.M oveNext()) {
using (XmlReader xmlReader = nodeIterator.Cu rrent.ReadSubtr ee()) {
if (xmlReader.Read ()) {
byte[] buffer = new byte[2048];
try {
int bytesRead = xmlReader.ReadE lementContentAs Base64(buffer,
0, buffer.Length);
Console.WriteLi ne("Read {0} bytes.", bytesRead);
}
catch (Exception e) {
Console.WriteLi ne("Error {0} reading key.", e);
}
}
}
}
thanx for your help. It does work. Thank you for enlightening me. :)
Aug 15 '06 #3

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

Similar topics

1
6817
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for elements, attributes, ".", and "..", plus also the "" predicate format is supported - however, only one predicate per path step is supported, and expr must be a relative path. 2. Poor performance
1
537
by: mvdevnull | last post by:
hey all currently i use the following piece of code to check if the string passed to me can be converted to base64, it is not very efficient and bad, can someone please suggest another of doing this private string ConvertBase64ToString(string content) { StringBuilder sb = new StringBuilder(); int i = content.GetUpperBound(0);
7
5484
by: Ot | last post by:
I posted this to the wrong group. It went to m.p.dotnet.languages.vb. Ooops. -------------------------------------------------------------------- I have this tiny problem. I have learned that an xpath expression can be bounded by either single or double quotation marks. But sometimes I want to search for a title containing both a single and double quote. Any way to do this?
6
10018
by: Banski | last post by:
Hi, Im quite new to XML in .Net. Im getting values from an xml file using XPath and sorting as you see in the code below. I cant figure out how to get the value of date with GetAttribute. Hope that this short description if enough and you can help to sort out this problem. Thanks in advance banski
2
29294
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, but the instructions I received do not seem correct. I need to covert a hex string to base64 and was told to 1. convert from the HEX string to a byte array 2. convert the byte array to Base64 encoding 3. the two encodings would produce the...
18
7724
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr); System.out.println(xp.evaluate(new InputSource(new FileInputStream("a.xml"))));
3
11045
by: AHanso | last post by:
Hey I am new to C# (My background is in Java), I am writing a C# application (that uses the Compact Framework) that communicates to a Java server. To login the server is expecting the password to be MD5 encrypted, and then base64 encoded. The Java client is doing this as follows, and it works with the server: private static String encodePassword(String password) { try {
6
3396
by: Hoss | last post by:
Hello. Because IE and Mozilla have such completely different XML implementations, I have created a class to handle general XML tasks, such as iterating over nodes given an xpath, evaluating an xpath, ect. It does all the branching for the different implementations within itself. I am working on a new method for this class that will, given an xpath, remove all nodes that match from the document. It works great in IE, heres the IE code.
10
4037
by: pycraze | last post by:
Hi , I am currently trying to implement base64 encoding and decoding scheme in C . Python has a module , base64 , that will do the encoding and decoding with ease . I am aware of OpenSSL having support for base64 encoding and decoding , but i will have to now implement both in C without using the openssl libraries . I was able to download a code w.r.t. base 64 encoding and decoding . I am attaching the code below .
0
8573
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8222
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7002
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6057
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5510
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2531
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 we have to send another system
1
1672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.