[R] question about XML (package)

Stephen C. Upton upton at mitre.org
Fri Feb 21 13:25:03 CET 2003


Ott,

I get the same thing on windows version. If you set "trim=FALSE" in the
xmlTreeParse function call, it works. I suspect xmlTreeParse is trimming
a little too much! But xmlTreeParse(with trim=TRUE) also works when the
first character is a non-digit - see below. We'll probably need to look
at the source code, unless someone else has better insight.

> a <- xmlTreeParse("test.xml",trim=FALSE)
> a$doc
$file
[1] "test.xml"

$version
[1] "1.0"

$children
$children$fields
 <fields>


  <v1>
  1
  </v1>


  <v2>
   2
  </v2>


  <v3>
   3
  </v3>


 </fields>

However, it also works when the first character is a non-digit - so far.
Here's a revised test.xml file:
<?xml version="1.0"?>
<fields>
<v1>a1 </v1>
<v2>2 </v2>
<v3> 3</v3>
</fields>

> a <- xmlTreeParse("test.xml")
> a
$doc
$file
[1] "test.xml"

$version
[1] "1.0"

$children
$children$fields
 <fields>
  <v1>
  a1
  </v1>
  <v2>
  </v2>
  <v3>
  3
  </v3>
 </fields>

HTH
steve


-------------------------------
> version
         _
platform i386-pc-mingw32
arch     i386
os       mingw32
system   i386, mingw32
status
major    1
minor    6.2
year     2003
month    01
day      10
language R  -

Ott Toomet wrote:

> Hi,
>
> I have a problem with spacing in XML files when reading them with
> xmlTreeParse.  I don't know the exact specification of xml but
> according what I have red before it should work.
>
> consider a tiny test.xml file:
>
> <?xml version="1.0"?>
> <fields>
> <v1>1 </v1>
> <v2> 2 </v2>
> <v3> 3</v3>
> </fields>
>
> i.e. I have three fields v1, v2 and v3 which differ only by spacing.
> Now when reading it as
>
> > a <- xmlTreeParse("/home/otoomet/tyyq/Taani-piir/andmed/test.xml")
> > a$doc$children$fields
>  <fields>
>   <v1>
>   </v1>
>   <v2>
>   2
>   </v2>
>   <v3>
>   3
>   </v3>
>  </fields>
>
> you can see that field v1 is empty.  Is it my misinterpretation, or a
> problem with the library?
>
> Thanks in advance,
>
> Ott
>
> -----------------
> > version
>          _
> platform i686-pc-linux-gnu
> arch     i686
> os       linux-gnu
> system   i686, linux-gnu
> status
> major    1
> minor    5.1
> year     2002
> month    06
> day      17
> language R
> ------------
> Package: XML
> Version: 0.93-1
> Date: 2002/11/06
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help




More information about the R-help mailing list