jsugarelli / xmlconvert Goto Github PK
View Code? Open in Web Editor NEWComfortably converting XML documents to dataframes and vice versa
Comfortably converting XML documents to dataframes and vice versa
Hi,
I am trying to use xmlconvert
function xml_to_df
to read an XML file that contains properties in both attributes and XML own elements. A simplified example :
<xml>
<country id="US" name="United States of America">
<property name="currency" value="USD"/>
</country>
</xml>
I manage to recover the properties (id, name) for each country, but not to list in addition currency.
To further complete my example, I also have nested (hierarchical) XML elements which I am not interested to extract (but they seem to interfere with the extraction. Completing my previous example :
<xml>
<country id="US" name="United States of America">
<property name="currency" value="USD"/>
<city id ="NYC" name = "New York">
<property name="area" value="121260"/>
<property name="population" value="8175133"/>
</city>
</country>
</xml>
I tried the following command but got the error message Error in recs[[i]] : subscript out of bounds
. I couldn't see right away where it went wrong, but I'm sure it's almost trivial.
test_df <- xmlconvert::xml_to_df("https://www.sec.gov/Archives/edgar/data/1477336/000176379920000063/ex102nov2020aart20191_1.xml",
records.tags = "assets",
fields = "tags")
Thanks for your work!
I am trying to open a xml file encoded in ISO-8859-1 (aka latin-1) using xmlconvert, yet even if I specify xml_encoding it still claims my input isn't proper UTF-8. My call and traceback are as follows:
> carbu_df <- xmlconvert::xml_to_df("./PrixCarburants_instantane.xml",
+ xml.encoding = "latin-1",
+ records.xpath = "//pdv | //prix",
+ fields = "attributes")
Error in read_xml.raw(charToRaw(enc2utf8(x)), "UTF-8", ..., as_html = as_html, :
Input is not proper UTF-8, indicate encoding !
Bytes: 0xE8 0x73 0x2D 0x4C [9]
> traceback()
4: read_xml.raw(charToRaw(enc2utf8(x)), "UTF-8", ..., as_html = as_html,
options = options)
3: read_xml.character(text, encoding = xml.encoding)
2: xml2::read_xml(text, encoding = xml.encoding)
1: xmlconvert::xml_to_df("./PrixCarburants_instantane.xml", xml.encoding = "latin-1",
records.xpath = "//pdv | //prix", fields = "attributes")
Loading the file using xml2::read_xml("./PrixCarburants_instantane.xml", encoding="latin-1")
does work, and so does opening the file using Notepad and saving it as UTF-8 (which is a bit tedious). It appears to me that enc2utf8
and charToRaw
somehow isn't doing its job when being confronted with direct latin-1 input.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.