[Expat-bugs] [ expat-Bugs-1157018 ] not well-formed ( invalid
token) for Certain XML tags
SourceForge.net
noreply at sourceforge.net
Sun Apr 3 04:54:12 CEST 2005
Bugs item #1157018, was opened at 2005-03-04 14:56
Message generated for change (Comment added) made by nobody
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=110127&aid=1157018&group_id=10127
Category: XML::Parser (inactive)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: not well-formed ( invalid token) for Certain XML tags
Initial Comment:
Hello :
I have a well formed XML packet but xmlwf thows out
error on certain tags
<entry id="DS000011" version="1">
<timestamp date="2004-11-05" time="22:37:30"
zone="UNKNOWN"/>
<source mfp="99.99.99.99" service=""/>
<job_info result="success">
<sender email="adad.dadad at adad.com"
authenticated="false">adad.dadad</sender>
<scan_info page_count="1" size="ltr"/>
<email_info size="888827" method="embedded"
fileFormat="jpeg" colorSettings="color"
result="success">
<subject>test</subject>
<email_destination email="adad.dadad at adad.com"
type="to" result="success"/>
</email_info>
</job_info>
</entry>
There are lot of other tags before and after these tags (
as shown above ). If i remove this particular section the
xmlwf doesn;t show any error.
The exact error is
<LINE NO>:10 : not well-formed (invalid token)
10 is actually the column position. and in the lines
shown above , "=" is in the column position 10.
Is there any newer version that handles these kind of
tags ? or pl. suggest me a work around
----------------------------------------------------------------------
Comment By: Nobody/Anonymous (nobody)
Date: 2005-04-02 18:54
Message:
Logged In: NO
hello,
i am new to using xml parsers in C. i have been playing with
expat on a windows machine running cygwin and a gcc
compiler. The version i am using is 1.95.8. i have written a
code which i think is ok as its parsing the document ok to
certain extent only.its giving a invalid token error.i am
attachig the code and the contents of the xml file if any one
would point me to wher i might be making a mistake i would
really appreciate it.
the code is below
/*****************************************************************
* This program reads from an xml file and builds a tree that is
later used to populate the array structure of nics, cabs etc
*/
#include <stdio.h>
#include <stdlib.h>
#include "expat.h"
#define BUFFSIZE 18192
char Buff[BUFFSIZE];
int Depth;
struct node{
char *node_name; //name of the node
char **attr_name; //string list of
attribute name
char **attr_val; //array of values of the
attributes
char *text; //text that is associated
with this node
struct node **child; //array of children
that this node can have
struct node *parent; //pointer to the
parent of the current node
int child_no;
};
/*
This handler is called when ever a start tag is encountered in
the input stream
*/
static void XMLCALL
start(void *userData, const char *el, const char **attr)
{
struct node **temp_ptr = (struct node**)userData;
printf("i am in start\n");
add_node(temp_ptr, el);
}
/*
This handler is called when ever an end tag is encountered in
the input stream
*/
static void XMLCALL
end(void *userData, const char *el)
{
printf("i am in end\n");
struct node **temp_ptr = (struct node**)userData;
close_node(temp_ptr);
}
/*
This handler is called when ever a character tag is
encountered in the input stream
*/
static void XMLCALL
char_handle(void *userData, const XML_Char *s, int len){
char *data = (char *)s ; // pointer to the new string that
we construct
char *temp_data;
int i = len;
struct node **temp_ptr = (struct node**)userData;
if (len >1) {
while(i>0){
*temp_data = *data;
i--;
data++;
temp_data++;
}
*temp_data = '\0';
temp_data = temp_data - len;
printf("i am in char handle %s and len=%d\n",
temp_data,len);
}
add_text(temp_ptr,data);
}
void add_node(struct node **void_node_ptr, char *el ){
struct node* next_node_ptr = (struct node*)malloc(sizeof
(struct node*));
next_node_ptr->child_no = 0;
struct node *current_node_ptr = (struct node *)
*void_node_ptr;
// update the previous node with the address of the current
node
// current_node_ptr->child[current_node_ptr-
>child_no] = next_node_ptr;
//current_node_ptr->child_no++;
next_node_ptr->node_name = el;
next_node_ptr->parent = current_node_ptr;
current_node_ptr = next_node_ptr;
}
void add_text(struct node **void_node_ptr,char *data ){
struct node *current_node_ptr = (struct node *)
*void_node_ptr;
current_node_ptr->text = data;
//printf(" in add_text with %s", current_node_ptr-
>text);
}
void close_node(struct node **void_node_ptr ){
struct node *current_node_ptr = (struct node *)
*void_node_ptr;
current_node_ptr = current_node_ptr->parent;
}
void
main(int argc, char *argv[]){
printf("i am in main\n");
XML_Parser p = XML_ParserCreate(NULL);
if (! p) {
fprintf(stderr, "Couldn't allocate memory for parser\n");
exit(-1);
}
//char *testdata = "venu\0";
struct node *node_ptr = (struct node*)malloc(sizeof(struct
node*));
node_ptr->child_no = 0;
//struct node *current_node_ptr = node_ptr;
void *userData = (void *)node_ptr;
XML_SetElementHandler(p, start, end);
XML_SetCharacterDataHandler(p,char_handle);
XML_SetUserData(p, &userData);
FILE *fp;
int len;
int done=1;
fp = fopen("/cygdrive/c/master-project/C-
programming/test2.xml", "r");
len = fread(Buff, 1, BUFFSIZE, fp);
printf("bytes read are %d and buffer has %d\n", len,sizeof
(Buff));
fclose(fp);
//printf("i am here");
if (XML_Parse(p,Buff,len,done) == XML_STATUS_ERROR)
{
fprintf(stderr, "Parse error at line %d:\n%s\n",
XML_GetCurrentLineNumber(p),
XML_ErrorString(XML_GetErrorCode(p)));
exit(-1);
}
}
The contents of the file are
<a>
<b>
<c>kkkk</c>
</b>
<d>
<e>pppp</e>
</d>
</a>
thanks
venu
----------------------------------------------------------------------
Comment By: Karl Waclawek (kwaclaw)
Date: 2005-03-13 05:56
Message:
Logged In: YES
user_id=290026
Show us your code - you may have a problem there.
----------------------------------------------------------------------
Comment By: Nobody/Anonymous (nobody)
Date: 2005-03-04 15:02
Message:
Logged In: NO
Operating System is HP-UX.
----------------------------------------------------------------------
Comment By: Nobody/Anonymous (nobody)
Date: 2005-03-04 15:01
Message:
Logged In: NO
Operating System is HP-UX.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=110127&aid=1157018&group_id=10127
More information about the Expat-bugs
mailing list