You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Sarah Leitner <le...@spawar.navy.mil> on 2002/12/09 15:24:03 UTC

question... again

for some reason I couldn't get this question to deliver to the email list
Friday. So here it is. Hopefully it'll go through this time.

I've got lots of sample code for processing an entire XML document, but none
for extracting one or two pieces of data from the document. In our case, all
of our error messages will be in a separate document. I will then need to
use Xerces  to match the error message to the error code that the system
generated. How in the world do I do something like this?

Sarah


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


RE: question... again

Posted by Erik Rydgren <er...@mandarinen.se>.
Well make it....

<!xml version="foobar" encoding="foobar" standalone="yes"!>
<!doctype [
  <!ELEMENT errors (error*)>
  <!ELEMENT error EMPTY>
  <!ATTLIST error
     no ID #REQUIRED
     and the other stuff
  >
]>

<errors>
  <error no="_12345" .... />
</errors>

.... then dammit :)

(And read with validation ON. Btw, watch out for nasty syntax errors. They
hunt in large numbers....)

/ Erik


-----Original Message-----
From: David N Bertoni/Cambridge/IBM [mailto:david_n_bertoni@us.ibm.com]
Sent: den 9 december 2002 17:28
To: xerces-c-dev@xml.apache.org
Subject: RE: question... again






Two problems here:

   1. IDs are XML names, so they cannot be numbers.  They must start with
   either a letter or underscore:

      http://www.w3.org/TR/REC-xml#NT-Name

   2. You must declare the attribute as type ID in a DTD.  Otherwise, the
   parser will not consider them IDs, and they won't be available from
   getElementById().

      http://www.w3.org/TR/DOM-Level-2-Core/core.html#i-Document

Dave




                      "Erik Rydgren"
                      <erik.rydgren@man         To:
<xe...@xml.apache.org>
                      darinen.se>               cc:      (bcc: David N
Bertoni/Cambridge/IBM)
                                                Subject: RE: question...
again
                      12/09/2002 06:58
                      AM
                      Please respond to
                      xerces-c-dev




Well I would do it like this.

Add an ID attribute to all you error message description nodes with the
value of the error message.

Example:
  <error id="12345" text_english="Some error text" text_foo="Error text in
foo language"/>

Parse the error description document with DOM and save the document for
error lookups.
On the document do a GetElementByID() methodcall supplying the error
number.
The method returns the element with the matching id attribute. Do a
GetAttribute("text_english") on the returned element to get the error
description in english.
Just note that the id attributes MUST be unique. But that is no problem for
you because error numbers tend to be unique by default :)

Regards

Erik Rydgren
Mandarinen systems AB
Sweden

-----Original Message-----
From: Sarah Leitner [mailto:leitners@spawar.navy.mil]
Sent: den 9 december 2002 15:24
To: xerces-c-dev@xml.apache.org
Subject: question... again


for some reason I couldn't get this question to deliver to the email list
Friday. So here it is. Hopefully it'll go through this time.

I've got lots of sample code for processing an entire XML document, but
none
for extracting one or two pieces of data from the document. In our case,
all
of our error messages will be in a separate document. I will then need to
use Xerces  to match the error message to the error code that the system
generated. How in the world do I do something like this?

Sarah


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


RE: question... again

Posted by David N Bertoni/Cambridge/IBM <da...@us.ibm.com>.



Two problems here:

   1. IDs are XML names, so they cannot be numbers.  They must start with
   either a letter or underscore:

      http://www.w3.org/TR/REC-xml#NT-Name

   2. You must declare the attribute as type ID in a DTD.  Otherwise, the
   parser will not consider them IDs, and they won't be available from
   getElementById().

      http://www.w3.org/TR/DOM-Level-2-Core/core.html#i-Document

Dave



                                                                                                                                         
                      "Erik Rydgren"                                                                                                     
                      <erik.rydgren@man         To:      <xe...@xml.apache.org>                                                   
                      darinen.se>               cc:      (bcc: David N Bertoni/Cambridge/IBM)                                            
                                                Subject: RE: question... again                                                           
                      12/09/2002 06:58                                                                                                   
                      AM                                                                                                                 
                      Please respond to                                                                                                  
                      xerces-c-dev                                                                                                       
                                                                                                                                         



Well I would do it like this.

Add an ID attribute to all you error message description nodes with the
value of the error message.

Example:
  <error id="12345" text_english="Some error text" text_foo="Error text in
foo language"/>

Parse the error description document with DOM and save the document for
error lookups.
On the document do a GetElementByID() methodcall supplying the error
number.
The method returns the element with the matching id attribute. Do a
GetAttribute("text_english") on the returned element to get the error
description in english.
Just note that the id attributes MUST be unique. But that is no problem for
you because error numbers tend to be unique by default :)

Regards

Erik Rydgren
Mandarinen systems AB
Sweden

-----Original Message-----
From: Sarah Leitner [mailto:leitners@spawar.navy.mil]
Sent: den 9 december 2002 15:24
To: xerces-c-dev@xml.apache.org
Subject: question... again


for some reason I couldn't get this question to deliver to the email list
Friday. So here it is. Hopefully it'll go through this time.

I've got lots of sample code for processing an entire XML document, but
none
for extracting one or two pieces of data from the document. In our case,
all
of our error messages will be in a separate document. I will then need to
use Xerces  to match the error message to the error code that the system
generated. How in the world do I do something like this?

Sarah


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


RE: question... again

Posted by Erik Rydgren <er...@mandarinen.se>.
Well I would do it like this.

Add an ID attribute to all you error message description nodes with the
value of the error message.

Example:
  <error id="12345" text_english="Some error text" text_foo="Error text in
foo language"/>

Parse the error description document with DOM and save the document for
error lookups.
On the document do a GetElementByID() methodcall supplying the error number.
The method returns the element with the matching id attribute. Do a
GetAttribute("text_english") on the returned element to get the error
description in english.
Just note that the id attributes MUST be unique. But that is no problem for
you because error numbers tend to be unique by default :)

Regards

Erik Rydgren
Mandarinen systems AB
Sweden

-----Original Message-----
From: Sarah Leitner [mailto:leitners@spawar.navy.mil]
Sent: den 9 december 2002 15:24
To: xerces-c-dev@xml.apache.org
Subject: question... again


for some reason I couldn't get this question to deliver to the email list
Friday. So here it is. Hopefully it'll go through this time.

I've got lots of sample code for processing an entire XML document, but none
for extracting one or two pieces of data from the document. In our case, all
of our error messages will be in a separate document. I will then need to
use Xerces  to match the error message to the error code that the system
generated. How in the world do I do something like this?

Sarah


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org