Java String Strip stripNamespaceDeclarations(String xml)

Here you can find the source of stripNamespaceDeclarations(String xml)

Description

strip Namespace Declarations

License

Apache License

Declaration

public static String stripNamespaceDeclarations(String xml) 

Method Source Code

//package com.java2s;
/*/*from ww w . ja  va 2s  .c om*/
 * Copyright (c) 2010-2017 Evolveum
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<String> declarations = new ArrayList<>();

    public static String stripNamespaceDeclarations(String xml) {
        if (xml == null) {
            return null;
        }
        for (String declaration : declarations) {
            for (;;) {
                int i = xml.indexOf(declaration);
                if (i < 0) {
                    break;
                }
                int j = i + declaration.length();
                while (j < xml.length() && Character.isWhitespace(xml.charAt(j))) {
                    j++;
                }
                String before = xml.substring(0, i);
                String after = j < xml.length() ? xml.substring(j, xml.length()) : "";
                xml = before + after;
            }
        }
        int i = xml.indexOf('>');
        if (i > 0) {
            if (Character.isWhitespace(xml.charAt(i - 1))) {
                xml = xml.substring(0, i - 1) + xml.substring(i, xml.length());
            }
        }
        return xml;
    }
}

Related

  1. stripBadHTMLTags(String s)
  2. stripClassFromClassName(String className)
  3. stripExtension(String filename)
  4. stripLastElement(String str)
  5. stripLeadingSlash(String str)
  6. stripTags(final String tagged)
  7. stripTags(String html)
  8. stripTags(String in)
  9. stripTrailingChar(String input, char c)