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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:01:34+00:00 2026-06-17T06:01:34+00:00

In order to make some changes on XML file, I use the code below:

  • 0

In order to make some changes on XML file, I use the code below:

  public boolean run() throws Exception {
    XMLReader xr = new XMLFilterImpl(XMLReaderFactory.createXMLReader()) {

     public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
          if(AddRuleReq&& qName.equalsIgnoreCase("cp:ruleset"))
           {
             attributeList.clear();
             attributeList.addAttribute(uri, localName, "id", "int", Integer.toString(getNewRuleId()));
             super.startElement(uri, localName, "cp:rule", attributeList);
             attributeList.clear();
             super.startElement(uri, localName, "cp:conditions", attributeList);
             super.startElement(uri, localName, "SOMECONDITION", attributeList);
             super.endElement(uri, localName, "SOMECONDITION");
             super.endElement(uri, localName, "cp:conditions");
             super.startElement(uri, localName, "cp:actions", attributeList);
             super.startElement(uri, localName, "allow", attributeList);
             super.characters(BooleanVariable.toCharArray(), 0, BooleanVariable.length());
             super.endElement(uri, localName, "allow");
             super.endElement(uri, localName, "cp:actions");
           }
      }
};
  Source source = new SAXSource(xr, new InputSource(new StringReader(xmlString)));
  stringWriter = new StringWriter();
  StreamResult result = new StreamResult(stringWriter);
  Transformer transformer = TransformerFactory.newInstance().newTransformer();
  transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
  transformer.setOutputProperty(OutputKeys.INDENT, "yes");
  transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3");
  transformer.transform(source, result);
  return stringWriter.toString();
}

I have pasted a little part of it and it works. But with little differences.

What I expect to see is:

<cp:rule id="1">
  <cp:conditions>
    <SOMECONDITION/>
  </cp:conditions>
  <cp:actions>
  <allow>
    true
  </allow>
  </cp:actions>
</cp:rule>

What I see is:

<cp:rule id="1">
  <cp:conditions>
    <SOMECONDITION xmlns="urn:ietf:params:xml:ns:common-policy"/>
  </cp:conditions>
  <cp:actions>
  <allow xmlns="urn:ietf:params:xml:ns:common-policy">
    true
  </allow>
  </cp:actions>
</cp:rule>

The processed XML is also invalid according to my schema and unusable for the next time.

My question is that, how can I prevent this namespaces (as in this example, < SOMECONDITION xmlns=”urn:ietf:params:xml:ns:common-policy”/>) being added to child elements?

Thanks in advance..

  • 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-06-17T06:01:35+00:00Added an answer on June 17, 2026 at 6:01 am

    You are calling the startElement method for the allow tag with the wrong parameters, I’m surprised your xml processor is not throwing an error for this:

    super.startElement(uri, localName, "allow", attributeList);
    

    Here uri is the namespace uri of the cp:ruleset element which you got as a parameter, and localName is the name of the ruleset element. Correct should be the following, using an empty string as the namespace uri and matching values for qname and local name.

    super.startElement("", "allow", "allow", attributeList);
    

    The same applies to your other startElement/endElement calls, instead of

    super.startElement(uri, localName, "cp:rule", attributeList);
    

    It should be

    super.startElement(uri, "rule", "cp:rule", attributeList);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use SED to make some changes to a CUPS configuration file.
I'm try to make some changes to my ZenPhoto installation in order so that
I am currently using Serialization in order to make deep copies of some autogenerated
I wish to make a nested for loop in order to process some files.
Sometimes in order to make our application more responsive and fast, we use client
Multiply users can call store procedure(SP) , that will make some changes to mytable
I am about to make some changes to an existing Apache C module to
A lot of times, I like to modify some lines of code in order
I have to make some changes to an e-commerce system to add some additional
I want to make changes to the purchase order report in OpenERP 6.1. Do

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.