Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4608166
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:48:24+00:00 2026-05-22T00:48:24+00:00

I have a function that builds and returns an XML document. I then want

  • 0

I have a function that builds and returns an XML document. I then want to insert this entire document inside another XML document. The problem that I seem to be having is that the XML header information is automatically added to the XML document, and then I get an error when trying to insert this. My code is as follows:

xmlElem = xmlDoc.createElement("MyNode");

tmpXmlStr = this.MyXmlBuildFunc();
xmlElem.innerXml(tmpXmlStr);

// Now try to add this to the main document
xmlParentNode.appendChild(xmlElem);

My function looks something like this:

str MyXmlBuildFunc()
{
    XmlDocument xmlOut;
    XmlNode curNod;
    XmlElement xmlElem;
    XmlElement xmlParentElem;
    ;

    xmlOut = XmlDocument::newBlank();

    xmlParentElem = xmlOut.createElement("MainNode");

    xmlElem = xmlOut.createElement("NodeName");
    xmlElem.innerText("NodeValue");
    xmlParentElem.appendChild(xmlElem);

    xmlOut.appendChild(xmlParentElem);

    return xmlOut.xml();
}

The error that I get is as follows:

Unexpected XML declaration. The XML declaration must be the first node in the document, and no white space characters are allowed to appear before it

Tracing it through, I believe this is caused by the XML definition being created by the XmlDocument build up in the function. How can I stop it doing this, ignore it, or get around this error some other way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:48:25+00:00Added an answer on May 22, 2026 at 12:48 am

    Try using return xmlParentElem.xml(); instead of return xmlOut.xml();.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>
I have a function that looks like this class NSNode { function insertAfter(NSNode $node)
I have a function that is effectively a replacement for print, and I want
I have a function that automatically exports a table into a CSV file, then
I want a function that reads in a file and returns the sum of
I have a search function that executes a stored procedure and returns results. If
I have a function that returns a hash, given certain parameters: build_message = function(from,
I have a function that gives me the following warning: [DCC Warning] filename.pas(6939): W1035
I have a function that gets x(a value) and xs(a list) and removes all
I have a function that takes, amongst others, a parameter declared as int privateCount

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.