If I have this value as the text within an attribute in my xml source:
“a2/PP00nFwWa7I8Jog7bcw==\n”
When I ask Nokogiri to return it, why does it return this:
"a2/PP00nFwWa7I8Jog7bcw== " (the last character I confirmed in the
debugger
as a space character). So it seems Nokogiri is converting the “\n” to a
space.
Is there a way to tell Nokogiri to return verbatim? I am dealing with
encrypted data and this modification which it is making to the xml
source is
significant?
I originally thought this might be a Ruby 1.9.2 issue but confirmed that
this is the same in 1.8.7. The difference is that REXML was returning
this
string as expected and now am converting to Nokogiri.
If I have this value as the text within an attribute in my xml source:
“a2/PP00nFwWa7I8Jog7bcw==\n”
When I ask Nokogiri to return it, why does it return this:
"a2/PP00nFwWa7I8Jog7bcw== " (the last character I confirmed in the
debugger
as a space character). So it seems Nokogiri is converting the “\n” to a
space.
Is there a way to tell Nokogiri to return verbatim? I am dealing with
encrypted data and this modification which it is making to the xml
source is
significant?
You probably need to use the xml:space attribute in your source
document, or at least that’s the impression I get from White Space | Microsoft Learn .
On Tue, Nov 2, 2010 at 3:22 PM, Marnen Laibow-Koser [email protected]wrote:
space.
Is there a way to tell Nokogiri to return verbatim? I am dealing with
encrypted data and this modification which it is making to the xml
source is
significant?
You probably need to use the xml:space attribute in your source
document, or at least that’s the impression I get from White Space | Microsoft Learn .
Thanks Marnen - that was a really good idea, I just tried it in the
console
and it does not seem to help for the “\n” (results below) is it possible
there is some other setting which would preserve the “\n”? This is
really
strange to me as these characters are within a string literal… but it
actually does also surprise me about the spaces.
Cant seem to find an answer to this on google:
Is there a way to tell Nokogiri to return verbatim? I am dealing with
console and it does not seem to help for the “\n” (results below) is it
children=[#<Nokogiri::XML::Element:0x12ff71e name=“BORROWER”
with xml:space="preserve"
">]>]>
=> "<BORROWER xml:space="preserve"
Sorry for all the addl posts but also in CDATA!!! Can the chars “\n” never mean anything but newline in our world?
Sorry for all the addl posts but also in CDATA!!! Can the chars “\n” never mean anything but newline in our world?
Take a deep breath. I believe you are quoting your strings
incorrectly. Witness the following script, which behaves as expected
on Nokogiri 1.4.3.1 and libxml 2.7.6:
require 'rubygems'
require 'nokogiri'
xml = '<root><foo _SSN="a2/PP00nFwWa7I8Jog7bcw==\n">bar</foo></
Next time you may want to try the nokogiri-talk mailing list for a
quicker response from users of the library.
Thanks Mike, this does work when I try it in the console and you are
right,
has to do with quoting. What seems clear is that the entire xml has to
be
within single quotes, as if it is within double quotes then the \n gets
replaced. What I am not clear about is how to tell Ruby when I load the
file
(I am getting the xml out of a saved file), to put it in single rather
than
double quotes? Or is there a way to transform it after loading it. When
I am
reading the file in I get: