473,378 Members | 1,393 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,378 software developers and data experts.

Xerces How to Determine Line Number While Traversing DOM

I am using Xerces to read an XML file and load it into a DOM so I can update
it and subsequently serialize the updated DOM.

The problem I have is that as I traverse the DOM I would like to inform the
user of exceptional conditions in the file. However I cannot find any way
while doing a DOM traversal to determine the line number that a particular
Node occurs on, except to count all of the new-line characters which occur
in Text Nodes.

Am I missing something?

--
Jim Cobban jc*****@magma.ca
34 Palomino Dr.
Kanata, ON, CANADA
K2M 1M1
+1-613-592-9438
Jul 20 '05 #1
2 2835
Jim Cobban wrote:
I am using Xerces to read an XML file and load it into a DOM so I can update
it and subsequently serialize the updated DOM.

The problem I have is that as I traverse the DOM I would like to inform the
user of exceptional conditions in the file. However I cannot find any way
while doing a DOM traversal to determine the line number that a particular
Node occurs on, except to count all of the new-line characters which occur
in Text Nodes.

Am I missing something?


hi,

plug an error handler to your parser like this :
myDOMParser.setErrorHandler(myErrorHandler);
when an error occurred, the appropriate method will be called (see
org.xml.sax.ErrorHandler) with an instance of
org.xml.sax.SAXParseException that have the expected methods
getColumnNumber() and getLineNumber()
--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------

Jul 20 '05 #2

"Philippe Poulard" <Ph****************@SPAMsophia.inria.fr> wrote in message
news:bq**********@news-sop.inria.fr...
Jim Cobban wrote:
I am using Xerces to read an XML file and load it into a DOM so I can update it and subsequently serialize the updated DOM.

The problem I have is that as I traverse the DOM I would like to inform the user of exceptional conditions in the file. However I cannot find any way while doing a DOM traversal to determine the line number that a particular Node occurs on, except to count all of the new-line characters which occur in Text Nodes.

Am I missing something?


hi,

plug an error handler to your parser like this :
myDOMParser.setErrorHandler(myErrorHandler);
when an error occurred, the appropriate method will be called (see
org.xml.sax.ErrorHandler) with an instance of
org.xml.sax.SAXParseException that have the expected methods
getColumnNumber() and getLineNumber()


Thank you. That is useful to know. However the errors in question are not
in the syntax of the XML but rather in the semantics. These are therefore
not errors which Xerces can detect for itself, even given an appropriate
DTD. That is why I would like to be able to determine the line number while
traversing the DOM.
Jul 20 '05 #3

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

Similar topics

2
by: Bekkali Hicham | last post by:
hi, i have downloaded the latest version 2.4 of Xerces, and unziped it, i end up with a diectory hierarchy like this c:\xerces-2_4_0\XercesImpl.jar c:\xerces-2_4_0\XercesSamples.jar...
1
by: Alexey V. Dmitriev | last post by:
Hi, ALL! Try to parse my XML doc with Xerces2-J (v.2.2.0), but ErrorHandler return errors a course of this proccess. All needed features were turn on. BTW, validation under XMLSpy tool passed...
0
by: Jim Phelps | last post by:
After having memory leak issues with Xerces-c 2.3.0 for Solaris 2.7 for CC 6.2 I have decided to update to at least 2.4. I have downloaded the binary tarball and have installed it on my...
0
by: Dale Gerdemann | last post by:
I've been trying to use DOM level 3 with xerces-2_6_2. There's a sample called samples/DOM3.java, but I've had trouble with compilation. I've downloaded Xerces-J-bin.2.6.2 and...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
5
by: Harald Haspl | last post by:
Hello, I've appended a simple XML file and it's appropriate schema below. I want to validate the XML file against the schema with xerces-c. This example contains a section where colours are...
3
by: shaun roe | last post by:
a follow up with new problems from my previous post: I have xml encoded in a string with elements like &lt;myElement/&gt; e.g <codeFragment> &lt;myElement&gt;some text&lt;/myElement&gt; </codeFragment> I...
9
by: mstilli | last post by:
Hi, I am trying to use schema for server side validation using xerces to catch the validation errors. validating this XML: <Content4> <textarea13></textarea13>...
2
by: christian.eickhoff | last post by:
Hello Everyone, I am facing a problem which should be relatively easy to solve for XML or XERCES experts. I am parsing my XML instance using xerces-c SAXParser. For internal purposes, it is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.