Giter Site home page Giter Site logo

Comments (2)

pwaeckerle avatar pwaeckerle commented on June 20, 2024 1

Hi,
Thank you for your analysis and reply. I am aware my XML file is far from being clean. I did not even realised the fact that values being a tag instead of a value would be a problem.

I would be happy to try & test new functionalities !
Best,
Pierre

from xmlconvert.

jsugarelli avatar jsugarelli commented on June 20, 2024

Hi,

Thanks for the remarks and the example.

So far, xmlconvert cannot deal with cases in which both the field name and the field's value are attributes.

If you do

xmlconvert::xml_to_df("test.xml", records.tags = "country", 
                      fields = "tags", field.names = "name")

then you get:

  currency               New.York
1       NA |property~||property~|

The reason for the 'currency' NA is that in our call of xml_to_df() we say our fields are represented by tags and their names are given by their name attribute. But the tag identified by attribute name = 'currency' has no value. Instead the value is represented by another attribute, value, while xml_to_df() expects the value to be the value of the tag. This results in NA.

The second 'field', New.York, comes from the fact that the city (a direct descendant of our record element country) happens to have a name attribute, as well. So xml_to_df() thinks: Great, here is another field! It then retrieves the 'value' of that 'field', too, and that is the flattened hierarchy below city. This can be avoided by using the only.fields argument to specify the fields that will be extracted:

xmlconvert::xml_to_df("test.xml", records.tags = "country", 
                      fields = "tags", field.names = "name",
                      only.fields = "currency")

resulting in:

  currency
1       NA

I know, this is still not what you want, but it is due to the fact that xml_to_df() so far has no way of working with data where a field name/field value combination is represented by two different attributes of the same tag.

But this is an exciting feature that I will add to the next version of xmlconvert which will presumably be released around Christmas / New Year.

Best,
Joachim

from xmlconvert.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.