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

  • Home
  • SEARCH
  • 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 6931179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:32:38+00:00 2026-05-27T11:32:38+00:00

I need to create an XML document with the following structure: <?xml version=1.0 ?>

  • 0

I need to create an XML document with the following structure:

<?xml version="1.0" ?> 
<Cancelacion xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             RfcEmisor="VSI850514HX4" 
             Fecha="2011-11-23T17:25:06" 
             xmlns="http://cancelacfd.sat.gob.mx">
    <Folios>
        <UUID>BD6CA3B1-E565-4985-88A9-694A6DD48448</UUID> 
    </Folios>
</Cancelacion>

The structure MUST be that way. But I’m not very familiar with the namespace declaration for the XML Elements. I can correctly generate an XML with the following structure:

<?xml version="1.0" ?> 
<Cancelacion RfcEmisor="VSI850514HX4" 
             Fecha="2011-11-23T17:25:06" 
             xmlns="http://cancelacfd.sat.gob.mx">
    <Folios>
        <UUID>BD6CA3B1-E565-4985-88A9-694A6DD48448</UUID> 
    </Folios>
</Cancelacion>

But the problem is that I can’t get to include the xmls:xsd and xmlns:xsi correctly. The code for properly generating the previously mentioned code is:

// Crear un document XML vacío
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
dbfac.setNamespaceAware(true);
DocumentBuilder docBuilder;
docBuilder = dbfac.newDocumentBuilder();
Document doc = docBuilder.newDocument();
doc.setXmlVersion("1.0");
doc.setXmlStandalone(true);

Element cancelacion = doc.createElementNS("http://cancelacfd.sat.gob.mx","Cancelacion");
cancelacion.setAttribute("RfcEmisor", rfc);
cancelacion.setAttribute("Fecha", fecha);
doc.appendChild(cancelacion);

Element folios = doc.createElementNS("http://cancelacfd.sat.gob.mx", "Folios");
cancelacion.appendChild(folios);
for (int i=0; i<uuid.length; i++) {
    Element u = doc.createElementNS("http://cancelacfd.sat.gob.mx","UUID");
    u.setTextContent(uuid[i]);
    folios.appendChild(u);
}
  • 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-27T11:32:38+00:00Added an answer on May 27, 2026 at 11:32 am

    You can add additional namespaces by calling setAttributeNS method on the root element
    as shown in below example

    // get the root element
    Element rootElement = xmlDoc.getDocumentElement();
    
    // add additional namespace to the root element
    rootElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
    

    You can then add elements to a given namespace by using the method like below

    // append author element to the document element
    Element author = xmlDoc.createElement("xsd:element");
    

    Read this article for more details.

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

Sidebar

Related Questions

I need to manipulate an existing XML document, and create a new one from
I need to create an XML schema that validates a tree structure of an
I need to create an XML schema definition (XSD) that describes Java objects. I
I need to create program that creates a XML schema like below using System.Xml.XmlSchema
Now I'm working on a web project. I need to create a XML document
I need to create an XML document for a website service that shows products
I need to create a PHP script that receives XML input via an HTTP
I need to create a XML Document object using the NodeList. Can someone pls
I need to create an XML document from a piece of plain text and
I need to create XML in Perl. From what I read, XML::LibXML is great

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.