Skip to content

Conversation

@trisix
Copy link

@trisix trisix commented Mar 7, 2018

Update:

I found that Node of

<string name="cdata"><![CDATA[Line number 1.<br />Line number 2.]]></string>

will contain a NodeSet and the first item of that NodeSet will be a CDATA

Tried using is_a? to check the class but still not that familiar with ruby, so I ended up using string comparison.

--

Hi,

Try use following method as a workaround to fix #73 (as a newbie of ruby...)

http://www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/Node#cdata%3F-instance_method
https://github.com/sparklemotion/nokogiri/blob/master/lib/nokogiri/xml/node.rb#L454

Append the test you've written before.

Please take a look~

--

BTW I escape the string with CDATA to deal with #73 's problem for now

Turn

<string name="cdata"><![CDATA[Line number 1.<br />Line number 2.]]></string>

Into

<string name="cdata">Line number 1.&lt;br /&gt;Line number 2.</string>

But it's kind of exhausted for me or my coworker to edit all our strings...

converter = Babelish::Android2CSV.new(
:csv_filename => csv_filename,
:headers => headers,
:filenames => [filename])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.
Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument.

expected_output = [["html"], {filename => {"html" => "<![CDATA[<p>Text<p>]]>"}}]
converter = Babelish::Android2CSV.new(
:csv_filename => csv_filename,
:headers => headers,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.


expected_output = [["html"], {filename => {"html" => "<![CDATA[<p>Text<p>]]>"}}]
converter = Babelish::Android2CSV.new(
:csv_filename => csv_filename,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

filename = "test/data/android_cdata.xml"
headers = %w{variables german}

expected_output = [["html"], {filename => {"html" => "<![CDATA[<p>Text<p>]]>"}}]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space inside { missing.
Line is too long. [84/80]
Space inside } missing.

converter = Babelish::Android2CSV.new(
:csv_filename => csv_filename,
:headers => headers,
:filenames => [filename])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.
Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument.

expected_output = [["html"], {filename => {"html" => "<![CDATA[<p>Text<p>]]>"}}]
converter = Babelish::Android2CSV.new(
:csv_filename => csv_filename,
:headers => headers,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.


expected_output = [["html"], {filename => {"html" => "<![CDATA[<p>Text<p>]]>"}}]
converter = Babelish::Android2CSV.new(
:csv_filename => csv_filename,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

filename = "test/data/android_cdata.xml"
headers = %w{variables german}

expected_output = [["html"], {filename => {"html" => "<![CDATA[<p>Text<p>]]>"}}]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space inside { missing.
Line is too long. [84/80]
Space inside } missing.

@trisix trisix changed the title Feature/fix cdata Try Fix CDATA problem in android2csv.rb Mar 7, 2018
strings.merge!(node["name"] => '<![CDATA[' + node.inner_html + ']]>')
else
strings.merge!(node["name"] => node.inner_html)
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

if !node.nil? && !node["name"].nil?
strings.merge!(node["name"] => node.inner_html)
if node.cdata?
strings.merge!(node["name"] => '<![CDATA[' + node.inner_html + ']]>')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Line is too long. [81/80]

@trisix
Copy link
Author

trisix commented Mar 7, 2018

Looks like it's not working...

I'll try something else later.

parser.xpath("//string").each do |node|
if !node.nil? && !node["name"].nil?
strings.merge!(node["name"] => node.inner_html)
if "#{node.children.first.class}" == "Nokogiri::XML::CDATA"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer to_s over string interpolation.

@trisix
Copy link
Author

trisix commented Mar 7, 2018

@netbe Looks like it is working now

Please take a look~ Thanks~

:filenames => [filename])

output = converter.convert(false)

Copy link
Author

@trisix trisix Mar 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remove a line here which check if file exists.

Since the above convert has a false. I think the file will not exist?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

android2csv: CDATA content are removed

2 participants