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

write_xml does not work with R 4.0.0 #307

Closed
munozav opened this issue May 5, 2020 · 2 comments
Closed

write_xml does not work with R 4.0.0 #307

munozav opened this issue May 5, 2020 · 2 comments

Comments

@munozav
Copy link

munozav commented May 5, 2020

Dear all,
Thanks for your great package, it has helped me a lot!.
I don't know if this is the place to ask you, but after upgrading to version R 4.0.0, the write_xml function no longer works. Returns NULL without writing any xml files.

Thank you very much for any information you can provide to this macOS user.

x <- read_xml("<body>
  <p>Some <b>text</b>.</p>
  <p>Some <b>other</b> <b>text</b>.</p>
  <p>No bold here!</p>
</body>")

# Get only words in bold
boldWords <- xml_find_all(x, ".//b")

# Add each node in nodeset to a new document
boldDocument = xml_new_root('newBody')
for (child in boldWords) {
  xml_add_child(boldDocument, child, 'newBody')
}

# Save subset xml in a new file
tmp = tempfile(fileext = ".xml")
write_xml(boldDocument, file = tmp, options = 'as_xml')
@munozav munozav changed the title write_xml does not work after R updated write_xml does not work with R 4.0.0 May 5, 2020
@jimhester
Copy link
Member

it returns NULL, but it does write the file.

library(xml2)
x <- read_xml("<body>
  <p>Some <b>text</b>.</p>
  <p>Some <b>other</b> <b>text</b>.</p>
  <p>No bold here!</p>
</body>")

# Get only words in bold
boldWords <- xml_find_all(x, ".//b")

# Add each node in nodeset to a new document
boldDocument = xml_new_root('newBody')
for (child in boldWords) {
  xml_add_child(boldDocument, child, 'newBody')
}

# Save subset xml in a new file
tmp = tempfile(fileext = ".xml")
write_xml(boldDocument, file = tmp, options = 'as_xml')
#> NULL

readLines(tmp)
#> [1] "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"           
#> [2] "<newBody><b>text</b><b>other</b><b>text</b></newBody>"

Created on 2020-05-05 by the reprex package (v0.3.0)

@munozav
Copy link
Author

munozav commented May 5, 2020

Yes, thank you very much for making me realize that! Have a nice day!!

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

No branches or pull requests

2 participants