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 986247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:17:27+00:00 2026-05-16T05:17:27+00:00

Given the intitial XML (BPEL) file: <?xml version=1.0 encoding=UTF-8?> <process name=TestSVG2 xmlns=http://www.example.org targetNamespace=http://www.example.org xmlns:xsd=http://www.w3.org/2001/XMLSchema>

  • 0

Given the intitial XML (BPEL) file:

 <?xml version="1.0" encoding="UTF-8"?>
<process
    name="TestSVG2"
    xmlns="http://www.example.org"
    targetNamespace="http://www.example.org"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <sequence>
        <receive name="Receive1" createInstance="yes"/>
        <assign name="Assign1"/>
        <invoke name="Invoke1"/>
        <assign name="Assign2"/>
        <reply name="Reply1"/>
    </sequence>
</process>

I have written a function that uses JAXB in order to modify some data inside the XML.
The function is as follows:

public void editAction(String name, String newName) {
    Process proc;
    StringWriter sw = new StringWriter();
    JAXBContext jaxbContext = null;
    Unmarshaller unMarsh = null;
    Object obj = new Object();
    try {
        /* XML TO JAVA OBJECT */
        jaxbContext = JAXBContext.newInstance("org.example");
        unMarsh = jaxbContext.createUnmarshaller();
        obj = unMarsh.unmarshal(new File(path + "/resources/" + BPELFilename));
        proc = (Process) obj;
        Process.Sequence sequence = proc.getSequence();

        /* Determine which element needs to be edited */
       /* Do some editing , code wasn't included */

        /* OBJ Back to XML */
        Marshaller marsh = jaxbContext.createMarshaller();
        marsh.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        //marsh.setProperty("com.sun.xml.bind.namespacePrefixMapper", new CustomPrefixMapper());
        marsh.marshal(obj, new File(path + "/resources/" + BPELFilename));

    } catch (JAXBException e) {
        /* Be afraid */
        e.printStackTrace();
    }
}

The resulting XML after the JAXB-related editing is:

<!-- After -->
 <?xml version="1.0" encoding="UTF-8"?>
<ns0:process 
    name="TestSVG2" 
    targetNamespace="http://www.example.org" 
    xmlns:ns0="http://www.example.org">

    <ns0:sequence>
        <ns0:receive name="newName" createInstance="yes"/>
        <ns0:assign name="Assign1"/>
        <ns0:assign name="Assign2"/>
        <ns0:invoke name="Invoke1"/>
        <ns0:reply name="Reply1"/>
    </ns0:sequence>
</ns0:process>

Unfortunately the resulting XML, is not compliant to our application, as our XML parser crashes when is parsing the new XML.

So:

  • How do I remove the namespace ns0, in the resulting XML ?
  • How to I preserve the same header from the initial XML File (the xml:xsd is missing)?

Thanks!

  • 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-16T05:17:28+00:00Added an answer on May 16, 2026 at 5:17 am

    If you use the MOXy JAXB implementation you can do the following:

    Your domain objects:

    package example;
    
    import javax.xml.bind.annotation.XmlRootElement;
    
    @XmlRootElement
    public class Process {
    
    }
    

    Use that package annotation @XmlSchema

    @javax.xml.bind.annotation.XmlSchema( 
        namespace = "http://www.example.org", 
        xmlns = {
            @javax.xml.bind.annotation.XmlNs(prefix = "xsd", namespaceURI = "http://www.w3.org/2001/XMLSchema"),
        },
        elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) 
    package example;
    

    To use MOXy JAXB you need to add a jaxb.properties file in with your model classes with the following entry:

    javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
    

    This will produce the XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <process xmlns="http://www.example.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the URL (single line): http://test.example.com/dir/subdir/file.html How can I extract the following parts using
Given a (source) patch file, what's the easiest way to apply this patch on
Given a specific DateTime value, how do I display relative time, like: 2 hours
Given a Python object of any kind, is there an easy way to get
Given a select with multiple option's in jQuery. $select = $(<select></select>); $select.append(<option>Jason</option>) //Key =
Given a DateTime representing a person's birthday, how do I calculate their age in
Given an absolute or relative path (in a Unix-like system), I would like to
Given 2 rgb colors and a rectangular area, I'd like to generate a basic
Given this HTML: <ul id=topnav> <li id=topnav_galleries><a href=#>Galleries</a></li> <li id=topnav_information><a href=#>Information</a></li> </ul> And this
How do you give a C# auto-property an initial value? I either use the

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.