Re: [xml] Problem parsing a string



On 19.05.2004 13:55, Juan David Palomino wrote:

I don't know how parse a string with some \n inside.
I have this string:
res = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>";
 res += "<Message>";
 res += "<ResponsePingATM Type=\"Status\" Order=\"1\" PhoneNumber=\"899999999\" Response=\"1\">";
 res += "</ResponsePingATM>";
 res += "</Message>";

string without end of lines;
When i do doc = xmlParseMemory( res.c_str(), res.length());
cur = xmlDocGetRootElement(doc);
    ** cur->name is Message
cur = cur->xmlChildrenNode;
    ** cur->name is ResponsePingATM

The problem is that i receive the following string

 res = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
 res += "<Message>\n";
 res += "<ResponsePingATM Type=\"Status\" Order=\"1\" PhoneNumber=\"899999999\" Response=\"1\">\n";
 res += "</ResponsePingATM>\n";
 res += "</Message>";

string with end of lines;
When i do doc = xmlParseMemory( res.c_str(), res.length());
cur = xmlDocGetRootElement(doc);
    ** cur->name is Message
cur = cur->xmlChildrenNode;
    ** cur->name is text

Are there other ways to parse this string (cur->next not allowed) that ignores \n?
Thnak you to all.

No, sorry. The parser will never ignore anything. Doing so would break the XML specification.

Also, if you cannot do a cur-next, then something in your program is seriously broken. You cannot use DOM without full tree walk capability.

You can use XPath to select the nodes you need from the DOM. To avoid using cur->next in the result set, you will have to construct an extra XPath expression for every node you need. This means an XPath evaluation instead of doing a cur->next and checking the node type, that will bring the performance down.

Ciao,
Igor



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]