473,490 Members | 2,488 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Is <id> reserved and unusable in perl XML::Simple?

BeemerBiker
87 New Member
I cannot get the following code to work unless I
(1) Change <id> to anything else, or
(2) Add an empty section to the bottom of my xml file.

Could this be a bug in 5.10.1 ActivePerl or my test xml script is no good?

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. use XML::Simple;
  4. use XML::Parser;
  5. use Data::Dumper;
  6.  
  7. my @failxml = (
  8. "<tests>\n",
  9. "<test>\n",
  10. "<id>1</id>\n",
  11. "</test>\n",
  12. "<test>\n",
  13. "<id>2</id>\n",
  14. "</test>\n",
  15. "</tests>\n"
  16. );
  17.  
  18. my @passxml = (
  19. "<tests>\n",
  20. "<test>\n",
  21. "<id>1</id>\n",
  22. "</test>\n",
  23. "<test>\n",
  24. "<id>2</id>\n",
  25. "</test>\n",
  26. "<test>\n",
  27. "</test>\n",
  28. "</tests>\n"
  29. );
  30.  
  31. open (OUT, ">test.xml");
  32. print OUT @failxml;
  33. close (OUT);
  34.  
  35. my $testlist = XMLin('test.xml');
  36.  
  37. print Dumper($testlist);
  38.  
  39. foreach my $test (@{$testlist->{test}}) {
  40.         print $test->{id} ;
  41.     print " ..worked..\n";
  42. }
Change "fail" to "pass" at that "print OUT" statement to see it work, or change id to id1

thanks for looking at my newbie junk code.


====results follow====

C:\perl>test.pl
$VAR1 = {
'test' => {
'1' => {},
'2' => {}
}
};
Not an ARRAY reference at C:\perl\test.pl line 39.
====i changed fail to pass and repeated the test====
C:\perl>test.pl
$VAR1 = {
'test' => [
{
'id' => '1'
},
{
'id' => '2'
},
{}
]
};
1 ..worked..
2 ..worked..
Use of uninitialized value in print at C:\perl\test.pl line 40.
..worked..

C:\perl>
May 30 '10 #1
2 1823
toolic
70 Recognized Expert New Member
Try:

Expand|Select|Wrap|Line Numbers
  1. my $testlist = XMLin('test.xml', ForceArray => 1); 
I recommend switching from XML::Simple to XML::Twig in order to avoid such mysterious behavior.
May 30 '10 #2
BeemerBiker
87 New Member
Thanks - that did it. However, that forcearray also stopped hash's from working :-(
May 30 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

13
3374
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to...
6
12138
by: Lasse | last post by:
I have done this simple function, it seems to work as intended, to solve a problem i have had for a while. I couldnt find any sample around that was working for me. I would like to test it with...
4
7210
by: El Diablo | last post by:
Hi there, I'm trying dynamically generate extra rows in a table. So far this achieves this task within the tHead segment: theTable.tHead.appendChild(document.createElement('TR')) ....but...
2
12165
by: MOHSEN KASHANI | last post by:
Hi, I am trying to hide some form elements in a form by default and show/hide depending on which radio button is clicked. This is what I have but it is not working: <head> <style> ..noshow {...
10
6823
by: Brian W | last post by:
Hi All, I have a web user control that, among other things, provides Print this page, and Email this page functionality I have this script that is to execute on the click of the asp:hyperlinks ...
3
3475
by: Jim in Arizona | last post by:
Most of the asp.net learning I've done has been from books that were written during the 1.0 framework. I didn't have a copy of visual studio when I started reading them then I got a hold of VS 2005...
4
1878
by: martijn | last post by:
H!, Is it possible to get a <tag:id>value</tag:id> value ? When I do this: ----------------------------------------------------- theXML = """<?xml version="1.0"?> <title>The Fascist...
4
2467
by: Gustaf | last post by:
I'm sure I've got this working before, but I always forget how to do it, because CSS isn't intuitive in this case. I got a simple 2 column layout: <div id="container"> <div id="left"> </div>...
7
3601
by: pamelafluente | last post by:
The precious input given by Laurent, Martin, Benjamin about XMLHttpRequest in Javascript, has made me think that perhaps I could improve what I am currently doing by using Ajax. Let's make it...
1
1858
by: swiftalpha | last post by:
Aloha, Smallish problem: I know how to serialize objects and all, but this has me worried: Asume this class. Person is a nice simple object. public class PersonList : List<Person> {...
0
7108
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7142
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7352
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5445
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4875
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.