Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating newline node on JRuby #719

Closed
dworld-software opened this issue Jun 27, 2012 · 1 comment
Closed

Creating newline node on JRuby #719

dworld-software opened this issue Jun 27, 2012 · 1 comment
Assignees

Comments

@dworld-software
Copy link

I wrote creating newline node using EntityReference

require 'rubygems'
require 'nokogiri'

xml = <<EOF
<?xml version="1.0" ?>
<item></item>
EOF
doc = Nokogiri::XML xml

lf_node = Nokogiri::XML::EntityReference.new(doc, "#xa")
doc.xpath('/item').first.add_child(lf_node)
puts doc.to_xml

Nokogiri 1.4.7 returns valid xml what I expected.

 <?xml version="1.0"?>
 <item>&#xa;</item>

But Nokogiri 1.5.5 causes DOMException.

null:-1:in `createEntityReference': org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified.
    from XmlEntityReference.java:76:in `init'
    from XmlNode.java:291:in `rbNew'
    from XmlNode$s$0$0$rbNew.gen:65535:in `call'
    from DynamicMethod.java:219:in `call'
    from DynamicMethod.java:215:in `call'
    from CachingCallSite.java:332:in `cacheAndCall'
    from CachingCallSite.java:203:in `call'
    from test.rb:11:in `__file__'
    from test.rb:-1:in `load'
    from Ruby.java:697:in `runScript'
    from Ruby.java:690:in `runScript'
    from Ruby.java:597:in `runNormally'
    from Ruby.java:446:in `runFromMain'
    from Main.java:369:in `doRunFromMain'
    from Main.java:258:in `internalRun'
    from Main.java:224:in `run'
    from Main.java:208:in `run'
    from Main.java:188:in `main'

Is there anyway to create newline node?

@ghost ghost assigned yokolet Jul 7, 2012
@yokolet
Copy link
Member

yokolet commented Jul 7, 2012

It seems Xerces is unable to create EntityReference with the name starting with '#'. So, I changed internal node type from EntityReference to Text. The change was pushed in rev. 0d8c3f2 . Now, pure Java version behaves like libxml version.

@yokolet yokolet closed this as completed Jul 7, 2012
jvshahid added a commit that referenced this issue Jan 20, 2013
…ore info below).

The fix for #719 made ReferenceEntity nodes look like text nodes. This
caused normalization of the document (i.e. concatenating adjacent
nodes) to combine the reference entity node with any adjacent text
nodes and create a new text node. When converting the document to
a string it was impossible to know if the text came from a reference
entity or text node, or both, which caused entities to be printed
without the delimiters '&' and ';'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants