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

add ElementDecls to an internal subset #1639

Open
flavorjones opened this issue May 11, 2017 · 4 comments
Open

add ElementDecls to an internal subset #1639

flavorjones opened this issue May 11, 2017 · 4 comments

Comments

@flavorjones
Copy link
Member

The use case is transforming this XML:

<?xml version="1.0"?>
<!DOCTYPE arbitrary SYSTEM "https://127.0.0.1/some.dtd" [

    <!ENTITY test "Dereferenced!">

]>
<arbitrary>
  <child>&test;</child>
</arbitrary>

into this XML (note the additional element definition within the DTD):

<?xml version="1.0"?>
<!DOCTYPE arbitrary SYSTEM "https://127.0.0.1/some.dtd" [

    <!ENTITY test "Dereferenced!">
    <!ELEMENT new_element ANY>

]>
<arbitrary>
  <child>&test;</child>
</arbitrary>

Nokogiri doesn't have any functionality to create or manipulate element declarations. The ElementDecl class is pretty much read-only, meaning that if your XML has one, you can parse and inspect it.

See original nokogiri-talk thread for more details.

@tisba
Copy link

tisba commented Jun 27, 2019

Pardon me, if this makes no sense, but this would also allow something like this?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mydoc SYSTEM "mydoc.dtd" [
  <!ENTITY foo SYSTEM "./foo.xml">
]>
<root>&foo;</root>
]>

I'm having a hard time to understand how to get this using Nokogiri::XML::Builder 😢

@flavorjones
Copy link
Member Author

Similarly for AttributeDecl ... Nokogiri offers no way to dynamically modify the document DTD to add these declarations.

Side note: libxml2 does not support adding EntityDecl to the DTD at runtime.

As a workaround for anyone who comes across this limitation: a way to work around this, suggested in this SO post is to create a new doc by parsing the desired DTD, and then build the desired DOM tree within that document.

@flavorjones
Copy link
Member Author

Interesting side note: the JRuby implementation's parser, Xerces, does not support modifying the doctype!

https://xerces.apache.org/xerces-j/apiDocs/org/w3c/dom/Document.html#getDoctype()

So this is a feature that can only be implemented in CRuby, as far as I know.

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