require 'nokogiri'
# Create the documentdoc = Nokogiri::XML::Document.new()
# SYSTEM External IDdoc.create_internal_subset("arbitrary", nil, "https://127.0.0.1/some.dtd")
# Add an entity to an internal subsetNokogiri::XML::EntityDecl::new('test', doc, nil, nil, nil, "Dereferenced!")
# Create the root elementdoc.root = Nokogiri::XML::Element.new("arbitrary", doc)
# Create a child elementchild = Nokogiri::XML::Element.new("child", doc)
# Add the entity reference to the childchild.content = Nokogiri::XML::EntityReference.new(doc, "test")
# Add the child to the root elementdoc.root.add_child(child)
puts doc
<?xml version="1.0"?><!DOCTYPE arbitrary SYSTEM "https://127.0.0.1/some.dtd" [<!ENTITY test "Dereferenced!">]><arbitrary> <child>&test;</child></arbitrary>
child.content = Nokogiri::XML::EntityReference.new(doc, "test")
child.add_child Nokogiri::XML::EntityReference.new(doc, "test")
<child>&test;</child>
<child>&test;</child>
doc2 = Nokogiri::XML(doc.to_xml)puts doc2.to_xml
<child>&test;</child>
doc2 = Nokogiri::XML(doc.to_xml) {|config| config.noent}puts doc2.to_xml
<?xml version="1.0"?><!DOCTYPE arbitrary SYSTEM "https://127.0.0.1/some.dtd" [<!ENTITY test "Dereferenced!">]><arbitrary>
<child>Dereferenced!</child></arbitrary>
--
You received this message because you are subscribed to the Google Groups "nokogiri-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nokogiri-talk+unsubscribe@googlegroups.com.
To post to this group, send email to nokogi...@googlegroups.com.
Visit this group at https://groups.google.com/group/nokogiri-talk.
For more options, visit https://groups.google.com/d/optout.
On Mar 21, 2017, at 3:54 PM, Mike Dalessio <mike.d...@gmail.com> wrote:Hope this has been enlightening!
<?xml version="1.0"?> <!ENTITY test "Dereferenced!">
]><arbitrary>
<child>&test;</child></arbitrary>
<?xml version="1.0"?>
<!ENTITY test "Dereferenced!">
<!ELEMENT new_element ANY>
]><arbitrary> <child>&test;</child></arbitrary>
To unsubscribe from this group and stop receiving emails from it, send an email to nokogiri-tal...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to nokogiri-talk+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to nokogiri-talk+unsubscribe@googlegroups.com.