Hi Suzy,
at first sight, you are adding several "song" element to the document, and documents can only have one root node; try adding a "songs" root node first, and change the

            m_doc->appendChild(r);

into
            m_doc->getDocElement()->appendChild(r);

Hope this helps,
Alberto

At 12.39 13/03/2007 -0700, Suzy Creamcheese wrote:

I'm tryin to create an XML logging class, and adding to the log has brought
up some problems. Here's the basis of the class


    class DomXmlLog
    {

    public:

        static DomXmlLog * create(void);
        static DomXmlLog * create(const std::string & file);
        static DomXmlLog * instance(void);

        void log(const XMLCh * artist, const XMLCh * track, const XMLCh *
album);
        void serialize(const std::string & file = "");

    private:

        DomXmlLog(const std::string & file);
        DomXmlLog(void);
        ~DomXmlLog(void);

        std::string m_file;

        std::auto_ptr<DOMFilter> m_pp; // Custom
        std::auto_ptr<DOMErrorReporter> m_err; // Custom

        std::auto_ptr<XercesDOMParser> m_parser;
        std::auto_ptr<DOMDocument> m_doc;

        static DomXmlLog * m_instance;

    };


The problem seems to stem from the log function.


    void DomXmlLog::logSong(const XMLCh * artist, const XMLCh * track, const
XMLCh * album)
    {
        SYSTEMTIME t;
        ::GetLocalTime(&t);

        std::basic_stringstream<XMLCh> ss;
        ss << t.wYear << ":" << t.wMonth << ":" << t.wDay << ":" <<
t.wDayOfWeek << ":" << t.wHour << ":" << t.wMinute << ":" << t.wSecond <<
":" << t.wMilliseconds;

        DOMElement * r = m_doc->createElement(XS("song"));
        DOMElement * e = m_doc->createElementNS(0, XS("song"));

        e->setAttributeNS(0, XS("artist"), artist);
        e->setAttributeNS(0, XS("album"), album);
        e->setAttributeNS(0, XS("track"), track);
        e->setAttributeNS(0, XS("time"), ss.str().c_str());

        try
        {
            r->appendChild(e);
            m_doc->appendChild(r);
        }
        catch(DOMException & e)
        {
        // ...
        }
    }

So. When I am creating a new log, I use the default constructor, the m_doc
DOMDocument is simply a new DOMDocumentImpl. When I am creating this log
from an existing log file I do something like

    m_parser->parse(file.c_str());

    if(!m_err->errors())
    {
        m_doc.reset(m_parser->getDocument());
    }

And then when I try to add a new entry to the log, then
m_doc->appendChild(r) throws DOMException code=HIERARCHY_REQUEST_ERR msg="An
attempt was made to insert a node where it is not permitted".

Can I append to the DOMDocument returned by getDocument? I do not get like a
INVALID_MODIFICATION_ERR, but I do not know how to clone the document if I
cannot append to this one. Any ideas?
--
View this message in context: http://www.nabble.com/XML-Generation-Throws-a-HIERARCHY_REQUEST_ERR-tf3398097.html#a9461764
Sent from the Xerces - C - Users mailing list archive at Nabble.com.

Reply via email to