未转义的 '<'R 中的属性值错误中不允许 [英] Unescaped '<' not allowed in attributes values error in R

查看:85
本文介绍了未转义的 '<'R 中的属性值错误中不允许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多 XML 格式的原始"主题数据,我需要将它们读入数据表以处理一些汇总统计信息.我用于测试的程序为我提供了以下输出(文件中一个事件的片段):

I have a number of "raw" subject data in XML format that I need to read into a data table to process some summary statistics. The program I used for testing gives me the following output (snippet of one event within the file):

    <Event>
      <Data name="Relation1" value="<"></Data>
      <Data name="Relation2" value="4    R"></Data>
      <Data name="Group" value="0"></Data>
      <Data name="CorrResult" value="S"></Data>
      <Data name="Response" value="S"></Data>
      <Data name="RT" value="787"></Data>
      <Data name="Result" value="C"></Data>
      <Data name="Gap" value="0"></Data>
      <Data name="IntraGap" value="0"></Data>
      <Data name="ISI" value="0"></Data>
    </Event>

第一个数据字段Relation1"的值将始终为<"或>".有没有办法让 R 将其识别为数据值而不是新属性值的开始?我已经使用 XML 和 XML2R 包尝试了很多方法,但最终总是将错误排在长长的错误列表的顶部.

The first data field "Relation1" will always have a value as either "<" or ">". Is there a way I can ask R to recognize that as a data value and not the start of a new attribute value? I've tried a number of things using the XML and XML2R packages and always end up with the error at the top of a long list of errors.

推荐答案

In XML

或 &用作值是严格非法的.还有更多不是严格非法但最好避免的.请改用实体引用.所以你的 XML 文件会产生一个错误.< 的实体引用是 &lt; 和 > 是 &gt;

In XML < or & are strictly illegal to use as values. There are more which are not strictly illegal but are better avoided. Use an entity reference instead. So your XML file generates an error. The entity reference for < is &lt; and > is &gt;

如果你不能改变输出过程,你可以写一个过程以基于文本的方式改变文件;我的意思是,逐行读取文件.如果检测到relation1,则更改第一个<或 > 之后;之后它应该工作.我无法向您展示这是如何在 R 中完成的,因为我不知道该语言.

If you can't change the output procedure, you can write a procedure to change the file in a text-based way; I mean, read the file line by line. If relation1 is detected, change the first < or > after that; after that it should work. I can't show you how this is done in R as I don't know the language.

我使用以下来源作为参考.

I used the source below for reference.

http://www.w3schools.com/xml/xml_syntax.asp

这篇关于未转义的 '&lt;'R 中的属性值错误中不允许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆