473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Ignoring reading the record when the tag is <weight/>

Hi All,

I am trying to read the xml file below using java/xml API, such as
DocumentBuilderFactory, DocumentBuilder and so on.

Do you know if there is any java/xml class, I can use to be able to
ignore the first record below which doesn't have any weight value. The
tag is: <weight/>


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

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

Aug 13 '06 #1
8 1293
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!
BeGreen wrote:
Hi All,

I am trying to read the xml file below using java/xml API, such as
DocumentBuilderFactory, DocumentBuilder and so on.
Do you know if there is any java/xml class, I can use to be able to
ignore the first record below which doesn't have any weight value. The
tag is: <weight/>


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

<weight>A</weight>
</Record>
</root>
Aug 13 '06 #2
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!
BeGreen wrote:
Hi All,

I am trying to read the xml file below using java/xml API, such as
DocumentBuilderFactory, DocumentBuilder and so on.
Do you know if there is any java/xml class, I can use to be able to
ignore the first record below which doesn't have any weight value. The
tag is: <weight/>


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

<weight>A</weight>
</Record>
</root>
Aug 13 '06 #3
BeGreen wrote:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<root>
<Record>
<PartNo>01</PartNo>
<weight/>
<Record>
[...]
This is not well-formed, close the Record element with </Record>.
--
Johannes Koch
Spem in alium nunquam habui praeter in te, Deus Israel.
(Thomas Tallis, 40-part motet)
Aug 13 '06 #4
Johannes,

<weight/is well-formed. XML/Java API should be able to parse it, but
I am not having any luck!

Thanks!

Johannes Koch wrote:
BeGreen wrote:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<root>
<Record>
<PartNo>01</PartNo>
<weight/>
<Record>
[...]
This is not well-formed, close the Record element with </Record>.
--
Johannes Koch
Spem in alium nunquam habui praeter in te, Deus Israel.
(Thomas Tallis, 40-part motet)
Aug 13 '06 #5


BeGreen wrote:
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/>.
Sure it is, but your XML has the problem here

>><?xml version="1.0" encoding="ISO-8859-1" ?>
<root>
<Record>
<PartNo>01</PartNo>
<weight/>
<Record>
^^^^^^^^
where you need a closing tag </Recordinstead.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 13 '06 #6
BeGreen wrote:
Johannes Koch wrote:
>>BeGreen wrote:
>>><?xml version="1.0" encoding="ISO-8859-1" ?>
<root>
<Record>
<PartNo>01</PartNo>
<weight/>
<Record>

[...]
This is not well-formed, close the Record element with </Record>.
<weight/is well-formed. XML/Java API should be able to parse it, but
I am not having any luck!
I didn't talk about <weight/>. Please read again.
--
Johannes Koch
Spem in alium nunquam habui praeter in te, Deus Israel.
(Thomas Tallis, 40-part motet)
Aug 13 '06 #7
Martin, yes the closing tag is </Record>, sorry for the typo!

So far, my program is failing when executing the code below which is
used to to retrieve the Record where there is this empty tag without a
value, <weight/>

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

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

-----------------------------------------------------------------------------------------------
Martin Honnen wrote:
BeGreen wrote:
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/>.

Sure it is, but your XML has the problem here

><?xml version="1.0" encoding="ISO-8859-1" ?>
<root>
<Record>
<PartNo>01</PartNo>
<weight/>
<Record>
^^^^^^^^
where you need a closing tag </Recordinstead.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 13 '06 #8


BeGreen wrote:

So far, my program is failing when executing the code below which is
used to to retrieve the Record where there is this empty tag without a
value, <weight/>

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

if (node.getNodeName()=="weight") {
String weightvalue = node.getFirstChild().getNodeValue();
}
Well if the element weight is empty then it does not have any child
nodes so getFirstChild() returns null and you can't call a method (i.e.
getNodeValue) on null.
If you are using Java 1.5 then you can simply do e.g.
String weightvalue = node.getTextContent();
as Java 1.5 supports the DOM Level 3 Core.
If you are using Java 1.4 respectively DOM Level 2 then you could check e.g.
String weightvalue = node.getFirstChild() != null ?
node.getFirstChild().getNodeValue(): "";

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 13 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Nachi | last post by:
Hi, Urgent Help appreciated.... I am getting resultset with first condition and when try to get the resutlset from second condition i am getting the above error in SQL200. I know that i am...
2
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script...
18
by: Tuckers | last post by:
My question is, if I have created my own library which lives in its own install directory, to refer to its header file is it better to use #include "MyLibrary.h" or #include <MyLibrary.h> ...
8
by: Tom | last post by:
Hi I have an aspx page which has javascript to configure xmldata. I added breakpoint to the button method. When I click submit button, it did not go to those breakpoint and show the following...
1
by: JezB | last post by:
I'm binding a DataGrid web-control to data fetched from a database. However some of my data fields contain text that is within <...> characters - I notice that everything between the <> is...
10
by: Szabolcs Horvát | last post by:
Consider the attached example program: an object of type 'A' is inserted into a 'map<int, Am;'. Why does 'm;' call the copy constructor of 'A' twice in addition to a constructor call? The...
3
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt,...
2
by: Kniffel | last post by:
Hi Is there a possibility to make an <xsl:whenon more than one Selection? Not that way: <xsl:choose> <xsl:when a=test> Do this <xsl:when a=test2>
3
by: Josh Valino | last post by:
Hi, I have a client that has our product and in one of the aspx files, there is code like this: <%= SomePublicProperty %> where the public property returns a string. In the test...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.