Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.HashMap;

import java.util.Map;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    /**
     * Extract namespaces into a map for adding to the builder.
     * E.g. xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     * @param xml XML source
     * @return map of namespaces : URL, e.g. [ "xsd" : "http://www.w3.org/2001/XMLSchema" ]
     */
    private static Map<String, String> parseNamespaces(String xml) {

        Map<String, String> nsMap = new HashMap<String, String>();

        Pattern nsPat = Pattern.compile("xmlns:(\\w+)=\"([^\"]+)\"");
        Matcher nsMat = nsPat.matcher(xml);

        while (nsMat.find()) {
            String ns = nsMat.group(1);
            String url = nsMat.group(2);
            nsMap.put(ns, url);
        }

        return nsMap;
    }
}