Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » XMLValidator - PLEASE HELP!!!
XMLValidator - PLEASE HELP!!! [message #177217] Thu, 17 August 2006 16:04 Go to next message
JavaJ Missing name is currently offline JavaJ Missing nameFriend
Messages: 45
Registered: July 2009
Member
Hello everyone! I'm having a problem. I'm using the XMLValidator to try to
validate an xml file using a dtd. I created a small xml file with a dtd
file. I noticed that if the xml tags are broken (example: misspelled), i
get a null pointer exception when processing the xml file and have no good
info on where it broke, like line number, etc. Is there a different tool
to use for xml syntax or am i just totally confused? From you experience,
how should i handle this? Here is the java code, xml file and dtd file.
Thanks much!

Jason



XMLValidator validator = new XMLValidator();


InputStream iostream = null;

String xmlFile = "C:\\xml\\people.xml";
String dtdFile = "C:\\xml\\people.dtd";

try {
iostream = new BufferedInputStream(new FileInputStream(new
File(xmlFile)));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

XMLValidationReport report = null;

try {
report = validator.validate(dtdFile, iostream);
} catch (Exception e) {

System.out.println(e);

}

System.out.println(report);

String fileURI = report.getFileURI();

System.out.println(fileURI);

for (ValidationMessage message : report.getValidationMessages()) {


System.out.println("\t"+message);

}

}

xml file --

<!DOCTYPE com.xstream.Person-array SYSTEM "file:/C:/xml/people.dtd">
<com.xstream.Person-array>
<com.xstream.Person>
<name>Jason</name>
<age>26</age>
<children/>
</com.xstream.Peson> <!-- this Peson should be Person, this is the
error I'm trying to find -->
<com.xstream.Person>
<name>Donna</name>
<age>62</age>
<children>
<com.xstream.Person>
<name>Jason</name>
<age>26</age>
<children/>
</com.xstream.Person>
</children>
</com.xstream.Person>
</com.xstream.Person-array>

dtd file

<!DOCTYPE com.xstream.Person-array SYSTEM "file:/C:/xml/people.dtd">
<com.xstream.Person-array>
<com.xstream.Person>
<name>Jason</name>
<age>26</age>
<children/>
</com.xstream.Peson>
<com.xstream.Person>
<name>Donna</name>
<age>62</age>
<children>
<com.xstream.Person>
<name>Jason</name>
<age>26</age>
<children/>
</com.xstream.Person>
</children>
</com.xstream.Person>
</com.xstream.Person-array>
Re: XMLValidator - PLEASE HELP!!! [message #177256 is a reply to message #177217] Thu, 17 August 2006 20:36 Go to previous messageGo to next message
Lawrence Mandel is currently offline Lawrence MandelFriend
Messages: 486
Registered: July 2009
Senior Member
The XML validator expects a valid URI representing the file location.
Specify a valid URL to the files such as

String xmlFile = "file:///C:\\xml\\people.xml";
String dtdFile = "file:///C:\\xml\\people.dtd";

and I think your NPE will dissapear.

Note: If you're interested in XML validation outside of Eclipse you may
want to take a look at Apache Xerces [1]. The WTP XML validator reuses
Xerces under the covers.

Lawrence

[1]http://xerces.apache.org
Re: XMLValidator - PLEASE HELP!!! [message #177264 is a reply to message #177256] Thu, 17 August 2006 20:52 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------020206070403070504030202
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Lawrence,

I would highly recommend *never *using a "\" within a URI. It's really
not the same as a "/" and is treated just like a plain old character
when it occurs in a URI. This might not become evident until a relative
path is resolved against it...


lmandel@ca.ibm.com wrote:
> The XML validator expects a valid URI representing the file location.
> Specify a valid URL to the files such as
>
> String xmlFile = "file:///C:\\xml\\people.xml";
> String dtdFile = "file:///C:\\xml\\people.dtd";
>
> and I think your NPE will dissapear.
>
> Note: If you're interested in XML validation outside of Eclipse you may
> want to take a look at Apache Xerces [1]. The WTP XML validator reuses
> Xerces under the covers.
>
> Lawrence
>
> [1]http://xerces.apache.org
>


--------------020206070403070504030202
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Lawrence,<br>
<br>
I would highly recommend <b>never </b>using a "\" within a URI.&nbsp; It's
really not the same as a "/" and is treated just like a plain old
character when it occurs in a URI.&nbsp; This might not become evident until
a relative path is resolved against it...<br>
<br>
<br>
<a class="moz-txt-link-abbreviated" href="mailto:lmandel@ca.ibm.com">lmandel@ca.ibm.com</a> wrote:
<blockquote cite="midec2k0e$rfp$4@utils.eclipse.org" type="cite">
<pre wrap="">The XML validator expects a valid URI representing the file location.
Specify a valid URL to the files such as

String xmlFile = <a class="moz-txt-link-rfc2396E" href="file:///C:\\xml\\people.xml">"file:///C:\\xml\\people.xml"</a>;
String dtdFile = <a class="moz-txt-link-rfc2396E" href="file:///C:\\xml\\people.dtd">"file:///C:\\xml\\people.dtd"</a>;

and I think your NPE will dissapear.

Note: If you're interested in XML validation outside of Eclipse you may
want to take a look at Apache Xerces [1]. The WTP XML validator reuses
Xerces under the covers.

Lawrence

[1]<a class="moz-txt-link-freetext" href="http://xerces.apache.org">http://xerces.apache.org</a>
</pre>
</blockquote>
<br>
</body>
</html>

--------------020206070403070504030202--
Re: XMLValidator - PLEASE HELP!!! [message #177272 is a reply to message #177264] Thu, 17 August 2006 22:05 Go to previous message
JavaJ Missing name is currently offline JavaJ Missing nameFriend
Messages: 45
Registered: July 2009
Member
This is a multi-part message in MIME format.

------=_NextPart_000_0016_01C6C21F.4DE5D340
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Thanks Lawrence.....

Well, now using that "file:///c:\\" format for the dtdFile i'm getting =
syntax errors on hte report.getValidationMessages() but it's not =
validating against the dtd. I removed the DTD from the top of my xml =
file so my xml file will be independent of the dtd. Correct me if I'm =
wrong, but in the call "report =3D validator.validate()" method, the =
first param is the URI so "file:///C:\\blah\\file.dtd" in a string =
format, and then the second param is an input stream which is an input =
for the xml file, right? so like validate(string file path to dtd, =
input stream for xml file)? I don't want the DTD to be referenced in =
the xml file becuase i'm using XStream to create the xml file from a =
java object. Please advise.

--xml file
<com.xstream.Person-array>
<com.xstream.Person>
<name>Jason</name>
<qage>26</qage> <-- Bad Tag, should be age -->
<children />
</com.xstream.Person>
<com.xstream.Person>
<name>Donna</name>
<age>62</age>
<children>
<com.xstream.Person>
<name>Jason</name>
<age>26</age>
<children />
</com.xstream.Person>
</children>
</com.xstream.Person>
</com.xstream.Person-array>


--DTD

<!ELEMENT age (#PCDATA)>
<!ELEMENT com.xstream.Person-array (#PCDATA | com.xstream.Person)*>
<!ELEMENT name (#PCDATA)>
<!ELEMENT children (#PCDATA | com.xstream.Person)*>
<!ELEMENT com.xstream.Person (#PCDATA | name | age | children)*>

Thanks,
Jason
"Ed Merks" <merks@ca.ibm.com> wrote in message =
news:ec2ks3$p3e$1@utils.eclipse.org...
Lawrence,

I would highly recommend never using a "\" within a URI. It's really =
not the same as a "/" and is treated just like a plain old character =
when it occurs in a URI. This might not become evident until a relative =
path is resolved against it...


lmandel@ca.ibm.com wrote:=20
The XML validator expects a valid URI representing the file location.=20
Specify a valid URL to the files such as

String xmlFile =3D "file:///C:\\xml\\people.xml";
String dtdFile =3D "file:///C:\\xml\\people.dtd";

and I think your NPE will dissapear.

Note: If you're interested in XML validation outside of Eclipse you may=20
want to take a look at Apache Xerces [1]. The WTP XML validator reuses=20
Xerces under the covers.

Lawrence

[1]http://xerces.apache.org
=20

------=_NextPart_000_0016_01C6C21F.4DE5D340
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type =
content=3Dtext/html;charset=3DISO-8859-1>
<META content=3D"MSHTML 6.00.2900.2668" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY text=3D#000000 bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Thanks Lawrence.....</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Well, now using that "<A=20
href=3D"file:///c:\\">file:///c:\\</A>" format for the dtdFile i'm =
getting syntax=20
errors on hte&nbsp; report.getValidationMessages() but it's not =
validating=20
against the dtd.&nbsp; I removed the DTD from the top of my xml file so =
my xml=20
file will be independent of the dtd.&nbsp; Correct me if I'm wrong, but =
in the=20
call "report =3D validator.validate()" method, the first param is the =
URI so "<A=20
href=3D"file:///C:\\blah\\file.dtd">file:///C:\\blah\\file.dtd</A>" in a =
string=20
format, and then the second param is an input stream which is an input =
for the=20
xml file, right?&nbsp; so like validate(string file path to dtd, input =
stream=20
for xml file)?&nbsp; I don't want the DTD to be referenced in the xml =
file=20
becuase i'm using XStream to create the xml file from a java =
object.&nbsp;=20
Please advise.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>--xml=20
file<BR>&lt;com.xstream.Person-array&gt;<BR>&nbsp;&lt;com.xstream.Person&=
gt;<BR>&nbsp;=20
&lt;name&gt;Jason&lt;/name&gt;<BR>&nbsp;=20
&lt;qage&gt;26&lt;/qage&gt;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb s=
p;&nbsp;&nbsp;&nbsp;=20
&lt;-- Bad Tag, should be age --&gt;<BR>&nbsp; &lt;children=20
/&gt;<BR>&nbsp;&lt;/com.xstream.Person&gt; <BR>&nbsp;&lt;com.xstream.Perso=
n&gt;<BR>&nbsp;=20
&lt;name&gt;Donna&lt;/name&gt;<BR>&nbsp; =
&lt;age&gt;62&lt;/age&gt;<BR>&nbsp;=20
&lt;children&gt;<BR>&nbsp;&nbsp;=20
&lt;com.xstream.Person&gt;<BR>&nbsp;&nbsp;&nbsp;=20
&lt;name&gt;Jason&lt;/name&gt;<BR>&nbsp;&nbsp;&nbsp;=20
&lt;age&gt;26&lt;/age&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;children=20
/&gt;<BR>&nbsp;&nbsp; &lt;/com.xstream.Person&gt;<BR>&nbsp;=20
&lt;/children&gt;<BR>&nbsp;&lt;/com.xstream.Person&gt; <BR>&lt;/com.xstrea=
m.Person-array&gt;</FONT></DIV>
<DIV>&nbsp;</DIV><FONT face=3DArial size=3D2>
<DIV><BR>--DTD</DIV>
<DIV>&nbsp;</DIV>
<DIV>&lt;!ELEMENT age (#PCDATA)&gt;<BR>&lt;!ELEMENT =
com.xstream.Person-array=20
(#PCDATA | com.xstream.Person)*&gt;<BR>&lt;!ELEMENT name=20
(#PCDATA)&gt;<BR>&lt;!ELEMENT children (#PCDATA |=20
com.xstream.Person)*&gt;<BR>&lt;!ELEMENT com.xstream.Person (#PCDATA | =
name |=20
age | children)*&gt;</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks,<BR>Jason</FONT></DIV>
<BLOCKQUOTE=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Ed Merks" &lt;<A =
href=3D"mailto:merks@ca.ibm.com">merks@ca.ibm.com</A>&gt;=20
wrote in message <A=20
=
href=3D"news:ec2ks3$p3e$1@utils.eclipse.org">news:ec2ks3$p3e$1@utils.ecli=
pse.org</A>...</DIV>Lawrence,<BR><BR>I=20
would highly recommend <B>never </B>using a "\" within a URI.&nbsp; =
It's=20
really not the same as a "/" and is treated just like a plain old =
character=20
when it occurs in a URI.&nbsp; This might not become evident until a =
relative=20
path is resolved against it...<BR><BR><BR><A =
class=3Dmoz-txt-link-abbreviated=20
href=3D"mailto:lmandel@ca.ibm.com">lmandel@ca.ibm.com</A> wrote:=20
<BLOCKQUOTE cite=3Dmidec2k0e$rfp$4@utils.eclipse.org =
type=3D"cite"><PRE wrap=3D"">The XML validator expects a valid URI =
representing the file location.=20
Specify a valid URL to the files such as

String xmlFile =3D <A class=3Dmoz-txt-link-rfc2396E =
href=3D"file:///C:\\xml\\people.xml">"file:///C:\\xml\\people.xml"</A>;
String dtdFile =3D <A class=3Dmoz-txt-link-rfc2396E =
href=3D"file:///C:\\xml\\people.dtd">"file:///C:\\xml\\people.dtd"</A>;

and I think your NPE will dissapear.

Note: If you're interested in XML validation outside of Eclipse you may=20
want to take a look at Apache Xerces [1]. The WTP XML validator reuses=20
Xerces under the covers.

Lawrence

[1]<A class=3Dmoz-txt-link-freetext =
href=3D"http://xerces.apache.org">http://xerces.apache.org</A>
</PRE></BLOCKQUOTE><BR></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0016_01C6C21F.4DE5D340--
Previous Topic:Programmatically validate xml file (java.io.File) using webtools?
Next Topic:%WTP_Tests as menu item
Goto Forum:
  


Current Time: Thu Sep 19 01:16:01 GMT 2024

Powered by FUDForum. Page generated in 1.05284 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top