从列中获取信息

时间:2017-08-22 14:20:35

标签: r

我在R Studio的数据框中有这个专栏,我想在里面获取信息。这就是列中其中一行的样子:

<goal>
   <value>
      <comment>n</comment>
      <stats>
         <goals>1</goals>
         <shoton>1</shoton>
      </stats>
      <event_incident_typefk>71</event_incident_typefk>
      <elapsed>2</elapsed>
      <player1>43372</player1>
      <sortorder>0</sortorder>
      <team>8370</team>
      <id>2305454</id>
      <n>34</n>
      <type>goal</type>
      <goal_type>n</goal_type>
   </value>
   <value>
      <comment>n</comment>
      <stats>
         <goals>1</goals>
         <shoton>1</shoton>
      </stats>
      <event_incident_typefk>71</event_incident_typefk>
      <elapsed>4</elapsed>
      <player1>2983</player1>
      <sortorder>0</sortorder>
      <team>8603</team>
      <id>2305455</id>
      <n>30</n>
      <type>goal</type>
      <goal_type>n</goal_type>
   </value>
   <value>
      <comment>n</comment>
      <stats>
         <goals>1</goals>
         <shoton>1</shoton>
      </stats>
      <event_incident_typefk>71</event_incident_typefk>
      <elapsed>62</elapsed>
      <player1>358127</player1>
      <sortorder>0</sortorder>
      <team>8370</team>
      <id>2305677</id>
      <n>33</n>
      <type>goal</type>
      <goal_type>n</goal_type>
   </value>
</goal>

我想知道是否有办法让这样:ex。

目标目标Shoton

... N ....... 1 ......... 1

依旧......

1 个答案:

答案 0 :(得分:0)

您拥有的是XML字符串。您可以将其解析为转换为列表,并从那里执行您需要的所有操作。举个例子,按照你的要求:

<?php
use Carbon_Fields\Container;
use Carbon_Fields\Field;

class Test
{

    public function __construct()
    {
        add_action( 'carbon_fields_register_fields', array( $this, 'crb_attach_theme_options') );
        add_action( 'after_setup_theme', array( $this , 'crb_load' ) );
    }

    public function crb_load()
    {
        require_once( 'vendor/autoload.php' );
        \Carbon_Fields\Carbon_Fields::boot();
    }

    public function crb_attach_theme_options()
    {
        Container::make( 'theme_options', __( 'Plugin Options', 'crb' ) )
            ->add_fields( array(
                Field::make( 'text', 'crb_text', 'Text Field' ),
            ) );
    }

}

$wpTest = new Test();