0
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
    <xs:complexType>
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="BalanceForAwardDetails">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="ProjectID" type="xs:long" minOccurs="0"/>
                        <xs:element name="Appointed_Date" type="xs:dateTime" minOccurs="0"/>
                        <xs:element name="Finalization_Schedule_Date" type="xs:dateTime" minOccurs="0"/>
                        <xs:element name="Final_Proposal_Approval_Date" type="xs:dateTime" minOccurs="0"/>
                        <xs:element name="StartMonth_Date1" type="xs:dateTime" minOccurs="0"/>
                        <xs:element name="StartMonth_Date2" type="xs:dateTime" minOccurs="0"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:choice>
    </xs:complexType>
</xs:element>

Storing above code in String named as schemaString. Using Below code to parse string into XML

DocumentBuilderFactory factory =DocumentBuilderFactory.newInstance();
     DocumentBuilder builder = factory.newDocumentBuilder();                
     Document document = builder.parse(schemaString);

But above code is giving me error as below:

java.net.MalformedURLException: no protocol: 
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)

Is there anything wrong I am doing ?

ParthPatel
  • 114
  • 2
  • 18
  • 1
    If you had bothered to read [the API docs for the method you are trying to use](https://docs.oracle.com/javase/8/docs/api/javax/xml/parsers/DocumentBuilder.html#parse-java.lang.String-), you would have discovered that the argument is expected to contain a URI (in string form) *identifying* the document to parse, ***not the XML content itself***. – John Bollinger Oct 04 '17 at 17:33
  • You can parse data from a String by building a `StringReader` around it and an `InputSource` around that. Your `DocumentBuilder` can parse from that source. – John Bollinger Oct 04 '17 at 17:37
  • Possible duplicate of [How to parse a String containing XML in Java and retrieve the value of the root node?](https://stackoverflow.com/questions/8408504/how-to-parse-a-string-containing-xml-in-java-and-retrieve-the-value-of-the-root) – John Bollinger Oct 04 '17 at 17:40
  • You don't convert `String` into XML. The string value is already XML. You can *parse* (not convert) that XML *text* into a *DOM* memory object. DOM (Document Object Model) is not XML, it's a memory model representing data in a form that map directly to/from XML. XML is *text*. – Andreas Oct 04 '17 at 17:42

0 Answers0