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. 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/
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. :) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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);
|
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?
|
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
|
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...
| |
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"))));
|
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 {
|
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.
|
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 .
|
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...
|
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,...
| |
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |