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 Benoit Lefevre <be...@effix.fr> on 2001/06/26 11:35:55 UTC
what's wrong with my code ??
Hi.
First of all, i want to apologies for all the orthographic mistakes
you'll see in this mail, i'm not realy good in english.
Now here is my problem : In the programme i'm actualy develloping
with xerces C++, i'm catching an exception i cannot explain.
Could someone tell me what i'm doing wrong ??
Here is the code sample, comments are following :
Code Sample :
----------------------------------
// this methode build a new DOM tree and use this one in a
// initialisation operation.
void myclass::AddSomthing(Params ...)
{
// First, thanks to one of my data structure, i get back
// the DOM_Document i'm working on and i use it to
// create a new DOM_Element.
DOM_Element elem;
elem = personalDataStructure.getUserData().getOwnerDocument().createElement(DOMString("A_Tag"));
// Once this Element is create, i build a DOM_TreeWalker
// based on this node; this way i can re-use another of my
// functions that use a DOM_TreeWalker as parameter.
DOM_TreeWalker dtw;
dtw = msg.getOwnerDocument().createTreeWalker(msg, ALL_EXCEPT_TEXT , NULL, false);
// I add a few attributes to this element.
msg.setAttribute( DOMString("Att1") , DOMString("AttVal1") );
msg.setAttribute( DOMString("Att2") , DOMString("AttVal2") );
...
// finaly i call the function that i want to re-use with the
// DOM_TreeWalker passed as argument.
testAndAdd(dtw);
}
// This methode performe some test on a DOM tree throught
// the DOM_TreeWalker passed in the Args List. Then it add
// the tree to another DOM_Element if this tree has no parents
void myclass::testAndAdd(DOM_TreeWalker &dtw)
{
// first i get back the DOM_Element lying behind the
// DOM_TreeWalker.
DOM_Element elem = (DOM_Element &) dtw.getCurrentNode();
// then i performe a few test on it
if( elem.getAttribute ...... )
.....
// finally if this element node have no parents, i append
// it to another DOM_Element.
bool orphan = (elem.getParentNode() == NULL);
if( orphan )
{
// before performing the "appendChild", i test
// the compatibility.
if( elem.getOwnerDocument() == futurFather.getOwnerDocument() )
futurFather.appendChild(elem); /* THE EXCPETION IS THROWN HERE */
else
{
// a personal exception is thrown if there is
// no compatibility
throw MyException();
exit(0);
}
}
}
----------------------------------
The exception i'm catching is of type DOM_DOMException
with an error code of 3. This one is thrown when execution flow
reach the "futurFather.appendChild(elem);" line after a call to
my methode AddSomething.
The place where this exception is thrown is indicate in the code
sample.
This mean according to the Documentation of the DOM_Node::appendChild
methode that i've tryed to :
- either insert a node of the wrong type (which is not the case).
- or to append one of his ancestor to the father node. this is
impossible because the node i want to insert have been
build on the fly during the call of "AddSomthing".
So if you have an advice or an idea of what i'm missing, it will be of
a great help for me.
Thanks.
benoit lefevre.
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: DOMPrint with chCR/chLF
Posted by Hal DeVore <ha...@acm.org>.
>>>>> On Thu, 28 Jun 2001, "Kent" == Kent Dahl wrote:
Kent> I don't remember the reference, anyone care to confirm or
Kent> unconfirm?
The following is from: http://www.w3.org/TR/REC-xml
2.11 End-of-Line Handling
XML parsed entities are often stored in computer files
which, for editing convenience, are organized into
lines. These lines are typically separated by some
combination of the characters carriage-return (#xD) and
line-feed (#xA).
To simplify the tasks of applications, the characters
passed to an application by the XML processor must be
as if the XML processor normalized all line breaks
in external parsed entities (including the document
entity) on input, before parsing, by translating both the
two-character sequence #xD #xA and any #xD that is not
followed by #xA to a single #xA character.
...
3.3.3 Attribute-Value Normalization
Before the value of an attribute is passed to the
application or checked for validity, the XML processor
must normalize the attribute value by applying the
algorithm below, or by using some other method such that
the value passed to the application is the same as that
produced by the algorithm.
1.All line breaks must have been normalized on input to
#xA as described in 2.11 End-of-Line Handling, so the
rest of this algorithm operates on text normalized in
this way.
[[ more details elided ]]
--Hal
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: DOMPrint with chCR/chLF
Posted by Kent Dahl <ke...@trustix.com>.
Stefan Berglund wrote:
> static const XMLCh gXMLDecl4[] =
> {
> chDoubleQuote, chQuestion, chCloseAngle
> , chCR, chLF, chNull
> };
>
> Couldn't this be a problem in Unix ? CR/LF can cause a ^M character in some
> cases? Is the XML standard saying that there should be a new line
> after the declaration section, or could the gXMLDecl4 constant end with
> chNull directly after the chCloseAngle?
I seem to recall something about only one of these (CR or LF) being
permitted in XML, and that a combination of CR/LF must be converted to
the legal one by the parser, meaning you can have CR/LF in the valid XML
file(which in turn makes it editable even in Windows Notepad), but you
can't have it in the XML data...
I don't remember the reference, anyone care to confirm or unconfirm?
--
<[ Kent Dahl ]>================<[ http://www.stud.ntnu.no/~kentda/ ]>
)____(stud.techn.;ind.øk.data)||(softwareDeveloper.at(Trustix))_(
/"Opinions expressed are mine and not those of my Employer, "\
( "the University, my girlfriend, stray cats, banana fruitflies, " )
\"nor the frontal lobe of my left cerebral hemisphere. "/
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
DOMPrint with chCR/chLF
Posted by Stefan Berglund <st...@telia.se>.
Hello,
I'm having problems with my app, I've borrowed the functionality of the
DOMPrint example to get my parsed XML to a string,
and when it "writes out" the XML_DECL_NODE, it uses the constant:
static const XMLCh gXMLDecl4[] =
{
chDoubleQuote, chQuestion, chCloseAngle
, chCR, chLF, chNull
};
Couldn't this be a problem in Unix ? CR/LF can cause a ^M character in some
cases? Is the XML standard saying that there should be a new line
after the declaration section, or could the gXMLDecl4 constant end with
chNull directly after the chCloseAngle?
Hmm now when checking, I see ENTITY_NODE also has chCR, chLF written out, is
this a must?
I'd rather put it all on the same line if it's ok with standards etc??
/Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: what's wrong with my code ??
Posted by Stefan Berglund <st...@telia.se>.
----- Original Message -----
> void myclass::testAndAdd(DOM_TreeWalker &dtw)
>...............
> {
> // first i get back the DOM_Element lying behind the
> // DOM_TreeWalker.
> DOM_Element elem = (DOM_Element &) dtw.getCurrentNode();
>
> // then i performe a few test on it
> if( elem.getAttribute ...... )
> .....
>
> // finally if this element node have no parents, i append
> // it to another DOM_Element.
> bool orphan = (elem.getParentNode() == NULL);
> if( orphan )
> {
> // before performing the "appendChild", i test
> // the compatibility.
> if( elem.getOwnerDocument() == futurFather.getOwnerDocument() )
------------------------------------
Maybe you have to "create place" for a new element in the document before
you append it,
something like:
DOM_Element newelem =
futurFather.getOwnerDocument().createElement(elem.getNodeName());
newelem = elem.clone(true);
futurFather.appendChild(newelem); (instead of next line)
???
------------------------------------
> futurFather.appendChild(elem); /* THE EXCPETION IS THROWN
HERE */
> else
> {
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org