Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   DocumentBuilder's parse method is not able to read a tag such as this one <weight/> (http://www.velocityreviews.com/forums/t363949-documentbuilders-parse-method-is-not-able-to-read-a-tag-such-as-this-one-weight.html)

BeGreen 08-13-2006 02:21 AM

DocumentBuilder's parse method is not able to read a tag such as this one <weight/>
 
Hi All,

javax.xml.parsers.DocumentBuilder's parse method is not able to parse
the xml file, when
the record has an empty tag without a value, such as <weight/>.

Any Java class, you may know which can parse that tag successfully or
even ignore it?
Thanks!

see below a sample of my xml file:



<?xml version="1.0" encoding="ISO-8859-1" ?>
<root>
<Record>
<PartNo>01</PartNo>
<weight/>
<Record>
<Record>
<PartNo>02</PartNo>


<weight>A</weight>
</Record>
</root>


=?ISO-8859-1?Q?Arne_Vajh=F8j?= 08-13-2006 02:36 AM

Re: DocumentBuilder's parse method is not able to read a tag suchas this one <weight/>
 
BeGreen wrote:
> javax.xml.parsers.DocumentBuilder's parse method is not able to parse
> the xml file, when
> the record has an empty tag without a value, such as <weight/>.
>
> Any Java class, you may know which can parse that tag successfully or
> even ignore it?
> Thanks!
>
> see below a sample of my xml file:
>
>
>
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> <root>
> <Record>
> <PartNo>01</PartNo>
> <weight/>
> <Record>
> <Record>
> <PartNo>02</PartNo>
>
>
> <weight>A</weight>
> </Record>
> </root>


Java parses that XML just fine.

Assuming you change the bad <Record> to </Record> so
the XML becomes wellformed !

Arne

BeGreen 08-13-2006 02:42 AM

Re: DocumentBuilder's parse method is not able to read a tag such as this one <weight/>
 
Arne, sorry for that. Actually I forgot the the forward slash on the
record, it's:

<Record>
<PartNo>01</PartNo>
<weight/>
</Record>



My only problem is to parse an empty tag with this format <weight/>




<Record> t</Record>
Arne Vajh°j wrote:
> BeGreen wrote:
> > javax.xml.parsers.DocumentBuilder's parse method is not able to parse
> > the xml file, when
> > the record has an empty tag without a value, such as <weight/>.
> >
> > Any Java class, you may know which can parse that tag successfully or
> > even ignore it?
> > Thanks!
> >
> > see below a sample of my xml file:
> >
> >
> >
> > <?xml version="1.0" encoding="ISO-8859-1" ?>
> > <root>
> > <Record>
> > <PartNo>01</PartNo>
> > <weight/>
> > <Record>
> > <Record>
> > <PartNo>02</PartNo>
> >
> >
> > <weight>A</weight>
> > </Record>
> > </root>

>
> Java parses that XML just fine.
>
> Assuming you change the bad <Record> to </Record> so
> the XML becomes wellformed !
>
> Arne



BeGreen 08-13-2006 02:46 AM

Re: DocumentBuilder's parse method is not able to read a tag such as this one <weight/>
 
Arne, sorry for that. Actually I forgot the forward slash on the
record, it's:
.................................................. .............................
<Record>
<PartNo>01</PartNo>
<weight/>
</Record>
.................................................. ............................


My only problem is to parse an empty tag with this format <weight/>



> Arne Vajh°j wrote:
> > BeGreen wrote:
> > > javax.xml.parsers.DocumentBuilder's parse method is not able to parse
> > > the xml file, when
> > > the record has an empty tag without a value, such as <weight/>.
> > >
> > > Any Java class, you may know which can parse that tag successfully or
> > > even ignore it?
> > > Thanks!
> > >
> > > see below a sample of my xml file:
> > >
> > >
> > >
> > > <?xml version="1.0" encoding="ISO-8859-1" ?>
> > > <root>
> > > <Record>
> > > <PartNo>01</PartNo>
> > > <weight/>
> > > <Record>
> > > <Record>
> > > <PartNo>02</PartNo>
> > >
> > >
> > > <weight>A</weight>
> > > </Record>
> > > </root>

> >
> > Java parses that XML just fine.
> >
> > Assuming you change the bad <Record> to </Record> so
> > the XML becomes wellformed !
> >
> > Arne



Michael Rauscher 08-13-2006 03:48 AM

Re: DocumentBuilder's parse method is not able to read a tag suchas this one <weight/>
 
BeGreen schrieb:
> Hi All,
>
> javax.xml.parsers.DocumentBuilder's parse method is not able to parse
> the xml file, when
> the record has an empty tag without a value, such as <weight/>.
>
> Any Java class, you may know which can parse that tag successfully or
> even ignore it?
> Thanks!


import java.io.*;
import javax.xml.parsers.*;

public class XMLTest {
public static final void main( String args[] ) throws Exception {
String xml =
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
"<root>\n" +
" <Record>\n" +
" <PartNo>01</PartNo>\n" +
" <weight/>\n" +
" </Record>\n" +
" <Record>\n" +
" <PartNo>2</PartNo>\n" +
" <weight>A</weight>\n" +
" </Record>\n" +
"</root>";

System.out.println( xml );
byte data[] = xml.getBytes("ISO-8859-1");
ByteArrayInputStream is = new ByteArrayInputStream( data );

DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
builder.parse(is);
is.close();
System.out.println("Done.");
}
}

Bye
Michael

Andrew Thompson 08-13-2006 06:14 AM

Re: DocumentBuilder's parse method is not able to read a tag such as this one <weight/>
 
Michael Rauscher wrote:
> BeGreen schrieb:

....
> > javax.xml.parsers.DocumentBuilder's parse method is not able to parse
> > the xml file, when
> > the record has an empty tag without a value, such as <weight/>.

....
> import java.io.*;
> import javax.xml.parsers.*;

.....
> System.out.println("Done.");
> }
> }


:-) That was a lovely little ..example. ;)

Andrew T.


=?ISO-8859-1?Q?Arne_Vajh=F8j?= 08-13-2006 02:43 PM

Re: DocumentBuilder's parse method is not able to read a tag suchas this one <weight/>
 
BeGreen wrote:
> My only problem is to parse an empty tag with this format <weight/>


That is not a problem.

Java XML parsers do not have a problem with that.

Arne

Michael Rauscher 08-13-2006 03:45 PM

Re: DocumentBuilder's parse method is not able to read a tag suchas this one <weight/>
 
Andrew Thompson schrieb:
>> import java.io.*;
>> import javax.xml.parsers.*;

> ....
>> System.out.println("Done.");
>> }
>> }

>
> :-) That was a lovely little ..example. ;)


Please provide a sscce ;)

Bye
Michael

BeGreen 08-13-2006 05:53 PM

Re: DocumentBuilder's parse method is not able to read a tag such as this one <weight/>
 

Hi Michael,

Yes, I can be able to parse the xml data, but my program is failing
when executing the code below, to retrieve the Record where there is
this empty tag without a value, <weight/>

<weight>something</weight> can be retrieved, but why not this one
<weight/>

As far as I am concerned <weight/> is a well-formed empty tag, and it
should be retrieved successfully!

There must an XML/Jave API to be able to retrieve it!


.................................................. .............................................

if (node.getNodeName()=="weight") {
String weightvalue = node.getFirstChild().getNodeValue();
}

-----------------------------------------------------------------------------------------------

For your info, Node is the object of the class: org.w3c.dom.Node





see below a sample of my xml file:


<?xml version="1.0" encoding="ISO-8859-1" ?>
<root>
<Record>
<PartNo>01</PartNo>
<weight/>
</Record>
<Record>
<PartNo>02</PartNo>


<weight>A</weight>
</Record>
</root>


BeGreen 08-13-2006 05:59 PM

Re: DocumentBuilder's parse method is not able to read a tag such as this one <weight/>
 
Arne,

See below my respone to Michael.

Yes, I can be able to parse the xml data, but to retrieve this kind of
empty tag <weight/> is my problem.

<weight> something </weight> can be retrieved though!

Thanks!


Arne Vajh°j wrote:
> BeGreen wrote:
> > My only problem is to parse an empty tag with this format <weight/>

>
> That is not a problem.
>
> Java XML parsers do not have a problem with that.
>
> Arne




All times are GMT. The time now is 10:07 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.