Sponsored Content
Full Discussion: libxml c
Top Forums Programming libxml c Post 302157920 by spids on Sunday 13th of January 2008 05:34:33 PM
Old 01-13-2008
libxml c

I've just started using libxml in c++, so far im able to parse a xml string. now i would like to replace <cms:CMSContent id="leftNav" /> with the string "left" and write the new xml out to cout; any ideas?

string.xml
Code:
<html xmlns:cms="http://www.test.com">
<body>
<cms:CMSContent id="leftNav" />
<cms:CMSContent id="rightNav" />
</body>
</html>

test.cpp - function streamFile(string s);
Code:
static void streamFile(string s) {
    xmlTextReaderPtr reader;
    int ret;
	
    reader = xmlReaderForMemory(s.c_str(),s.size(), NULL,NULL, 0);
    if (reader != NULL) {
        ret = xmlTextReaderRead(reader);
        while (ret == 1) {
            processNode(reader);
            ret = xmlTextReaderRead(reader);
        }
        xmlFreeTextReader(reader);
        if (ret != 0) {
		cout << "Failed to parse";	
        }
    } else {
	cout << "unable to open";

    }
static void
processNode(xmlTextReaderPtr reader) {
    const xmlChar *name, *value;

    name = xmlTextReaderConstName(reader);
    if (name == NULL)
	name = BAD_CAST "--";

    value = xmlTextReaderConstValue(reader);

    printf("%d %d %s %d %d", 
	    xmlTextReaderDepth(reader),
	    xmlTextReaderNodeType(reader),
	    name,
	    xmlTextReaderIsEmptyElement(reader),
	    xmlTextReaderHasValue(reader));
	//xmlTextReaderConstValue(reader));
    if (value == NULL)
	printf("\n");
    else {
        if (xmlStrlen(value) > 40)
            printf(" %.40s...\n", value);
        else
	    printf(" %s\n", value);
    }
}


Last edited by spids; 01-13-2008 at 08:55 PM..
 

4 More Discussions You Might Find Interesting

1. Programming

libxml c

i have xml file like this <root> <sree> <cnu value="cprogramming"\> </sree> </root> to retrieve the valuse of cnu element i tried the following code Code: void parseDoc() { xmlDocPtr doc; xmlNodePtr cur; doc = xmlParseFile("/usr/share/1.xml"); if (doc == NULL ) {... (1 Reply)
Discussion started by: phani_sree
1 Replies

2. Programming

[libxml++] DOmParser get node value

Hi I wrote the follow code: this->domParser = new xmlpp::DomParser(); this->domParser->set_validate(true); this->domParser->parse_file(*this->xmlFileName); this->doc = this->domParser->get_document(); xmlpp::Node* rootNode = this->doc->get_root_node(); xmlpp::Node::NodeList list =... (0 Replies)
Discussion started by: takeo.kikuta
0 Replies

3. Shell Programming and Scripting

How to nodetype as "ELEMENT_NODE" using xml::libxml in perl?

Hi, I am using xml::libxml. Here is the code. my $parser = XML::LibXML->new(); my $xmldoc = $parser->parse_file ("file.xml") || die("Could not parse config xml file\n"); my $root = $xmldoc->getDocumentElement()|| die("Could not get Document Element \n"); $id="121313131"; # For example... (2 Replies)
Discussion started by: vanitham
2 Replies

4. Programming

Help in libxml++ for Linux

Hi, Using libxml++-2.6, is it possible to change the xsi:noNamespaceSchemaLocation in the root element node? e.g. from <myxml xsi:noNamespaceSchemaLocation="ABC.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> : : </myxml> to <myxml... (1 Reply)
Discussion started by: tanlccc
1 Replies
QXmlEntityResolver(3qt) 												   QXmlEntityResolver(3qt)

NAME
QXmlEntityResolver - Interface to resolve external entities contained in XML data SYNOPSIS
All the functions in this class are reentrant when Qt is built with thread support.</p> #include <qxml.h> Inherited by QXmlDefaultHandler. Public Members virtual bool resolveEntity ( const QString & publicId, const QString & systemId, QXmlInputSource *& ret ) = 0 virtual QString errorString () = 0 DESCRIPTION
The QXmlEntityResolver class provides an interface to resolve external entities contained in XML data. If an application needs to implement customized handling for external entities, it must implement this interface, i.e. resolveEntity(), and register it with QXmlReader::setEntityResolver(). See also the Introduction to SAX2. See also QXmlDTDHandler, QXmlDeclHandler, QXmlContentHandler, QXmlErrorHandler, QXmlLexicalHandler, and XML. MEMBER FUNCTION DOCUMENTATION
QString QXmlEntityResolver::errorString () [pure virtual] The reader calls this function to get an error string if any of the handler functions returns FALSE. bool QXmlEntityResolver::resolveEntity ( const QString & publicId, const QString & systemId, QXmlInputSource *& ret ) [pure virtual] The reader calls this function before it opens any external entity, except the top-level document entity. The application may request the reader to resolve the entity itself (ret is 0) or to use an entirely different input source (ret points to the input source). The reader deletes the input source ret when it no longer needs it, so you should allocate it on the heap with new. The argument publicId is the public identifier of the external entity, systemId is the system identifier of the external entity and ret is the return value of this function. If ret is 0 the reader should resolve the entity itself, if it is non-zero it must point to an input source which the reader uses instead. If this function returns FALSE the reader stops parsing and reports an error. The reader uses the function errorString() to get the error message. SEE ALSO
http://doc.trolltech.com/qxmlentityresolver.html http://www.trolltech.com/faq/tech.html COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement. AUTHOR
Generated automatically from the source code. BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qxmlentityresolver.3qt) and the Qt version (3.3.8). Trolltech AS 2 February 2007 QXmlEntityResolver(3qt)
All times are GMT -4. The time now is 04:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy