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 Qian Xia <xi...@kick.gr.jp> on 2000/11/18 05:09:56 UTC
About AttrImpl()
I have an XML file which contains elements with the same tag name but
different in attributes. Let me write the example in the following:
<certification type="A">
<subtag1>data1</subtag1>
<subtag2>data2</subtag2>
</certification>
<certification type="B">
<subtag1>data1</subtag1>
<subtag2>data2</subtag2>
</certification>
Now I want to get all the nodes data under "certification " of type "A" , I
find that function
AttrImpl(DocumentImpl *ownerDocument, const DOMString &aName)
seems just the right way:
AttrImpl( certification, &(char c="A") )
But I don't know what's the return value of this function. When I read
AttrImpl.hpp, it says this file is part of the internal implementation of
the C++ XML DOM and should not be included or used directly by application
programs.
So, to solve my problem, can I use AttrImpl()?
Thanks a lot,
Qian Xia
_/_ Join those who intrigue you _/_
_/_ and try to become intriguing too _/_
_/_ ______________________________________________ _/_
_/_ Name : Qian Xia _/_
_/_ Email : xqianxia@ysb.nsd.co.jp _/_
_/_ ________________________________________________ _/_
Re: About AttrImpl()
Posted by Bill Schindler <de...@bitranch.com>.
"Qian Xia" <xi...@kick.gr.jp> wrote:
> <document>
> <certification type="A">
> <subtag1>data1</subtag1>
> <subtag2>data2</subtag2>
> </certification>
> <certification type="B">
> <subtag1>data1</subtag1>
> <subtag2>data2</subtag2>
> </certification
> </document>
>
> [ ... ]
>
> nodes = doc.getChildNodes;
>
> What puzzled me is that if the following return values are the same:
>
> nodes.getLength() and
> doc.getElementsByTagName("certification").getLength()
If your XML sample given above _exactly_ matches the XML you are parsing,
then Xerces should be throwing an error when it parses this document. The
document is not well-formed because the second certification element has a
syntax error in the end-tag. (It is missing the closing angle bracket.)
Anyway, I did a quick hack on the sample DOMCount and ran it against a
fixed version of your XML file. Here are the results:
testing.xml: 23 ms
7 elements
1 child nodes of doc
5 child nodes of n1
2 'certification' elements
And here is the code I added around line 230 of DOMCount.cpp:
DOM_Document doc = parser.getDocument();
unsigned int elementCount =
doc.getElementsByTagName("*").getLength();
unsigned int docChildCount =
doc.getChildNodes().getLength();
DOM_Node n1 = doc.getFirstChild();
unsigned int n1ChildCount = 0;
if ( n1 != 0 )
n1ChildCount = n1.getChildNodes().getLength();
unsigned int certCount =
doc.getElementsByTagName("certification").getLength();
// Print out the stats that we collected and time taken.
cout << xmlFile << ": " << duration << " ms" << endl
<< " " << elementCount << " elements" << endl
<< " " << docChildCount << " child nodes of doc" << endl
<< " " << n1ChildCount << " child nodes of n1" << endl
<< " " << certCount << " 'certification' elements" << endl;
The one child node of doc is the "document" element. The five child nodes
of n1 (i.e. the children of the "document" element) are the two
"certification" elements plus three text nodes. That all seems to be
working correctly. What values are you getting?
--Bill
Codes < 32 in nodes
Posted by Hugues Marty <hu...@isoft.fr>.
Hi there,
I have an xml document with "iso-8859-1" encoding. When there are some
characters which code are < 32 (except for 9, 10 and 13 -- tabs, line feed
and carriage return), for instance ^Z (26 or 0x1A) in my xml document, in
node values, the parser doesn't accept them/parse them correctly. It seems
like the parser does the parsing, but that some tags are ignored. I used
 to replace the characters, and it does the same thing. I also tested
with CDATA, same result.
Is there a way to have characters with code < 32 in my xml document? Or any
idea of what's wrong here?
Hugues.
Re: About AttrImpl()
Posted by Qian Xia <xi...@kick.gr.jp>.
----- Original Message -----
送信者 : Bill Schindler <de...@bitranch.com>
宛先 : <xe...@xml.apache.org>
送信日時 : 2000年 11月 18日 土曜日 22:25
件名 : Re: About AttrImpl()
| For an example of how you might access the attributes attached to an
| element, look at the sample DOMPrint.cpp, around line 572 (under "case
| DOM_Node::ELEMENT_NODE:"). There is a for-loop in that case that steps
| through all of the attributes for the element, accessing each attribute's
| value.
|
| To get all of the "certification" elements in the document, see
| DOM_Document::getElementsByTagName() which returns a DOM_NodeList. You can
| then step through the NodeList, looking for any elements that have
specific
| attribute values.
|
Thanks for the answer.
I'd like to rewrite my XML document here:
<document>
<certification type="A">
<subtag1>data1</subtag1>
<subtag2>data2</subtag2>
</certification>
<certification type="B">
<subtag1>data1</subtag1>
<subtag2>data2</subtag2>
</certification
</document>
There's the src:
doc = parser.getDocument();
nodes = doc.getChildNodes;
element = nodes.item(0);
nodemap = element.getAttributes();
What puzzled me is that if the following return values are the same:
nodes.getLength() and
doc.getElementsByTagName("certification").getLength() and
nodemap.getLength()
Thanks a lot,
_/_ Join those who intrigue you _/_
_/_ and try to become intriguing too _/_
_/_ _______________________________________ _/_
_/_ Name : Qian Xia _/_
_/_ Email : xqianxia@ysb.nsd.co.jp _/_
_/_ ____________________________________ _/_
Re: About AttrImpl()
Posted by Bill Schindler <de...@bitranch.com>.
"Qian Xia" <xi...@kick.gr.jp> wrote:
> Now I want to get all the nodes data under "certification " of type "A" , I
> find that function
>
> AttrImpl(DocumentImpl *ownerDocument, const DOMString &aName)
>
> seems just the right way:
> AttrImpl( certification, &(char c="A") )
>
> But I don't know what's the return value of this function. When I read
> AttrImpl.hpp, it says this file is part of the internal implementation of
> the C++ XML DOM and should not be included or used directly by application
> programs.
>
> So, to solve my problem, can I use AttrImpl()?
No. Even if you could use AttrImpl(), it would not solve your problem.
AttrImpl() is not a function, it is a constructor. It is used for creating
instances of the AttrImpl class. AttrImpl objects are used internally by
Xerces to represent XML attributes in a DOM tree. It is _not_ used to
search for attributes. (Note that your example would not work in any case.
The AttrImpl constructor uses a DocumentImpl parameter, not a DOM_Element
or an ElementImpl. I am not sure what your second example parameter is
supposed to represent -- but it is definitely not an object of type
DOMString.)
For an example of how you might access the attributes attached to an
element, look at the sample DOMPrint.cpp, around line 572 (under "case
DOM_Node::ELEMENT_NODE:"). There is a for-loop in that case that steps
through all of the attributes for the element, accessing each attribute's
value.
To get all of the "certification" elements in the document, see
DOM_Document::getElementsByTagName() which returns a DOM_NodeList. You can
then step through the NodeList, looking for any elements that have specific
attribute values.
You should look at the DOM documentation at http://www.w3.org/DOM/ and the
Xerces-C documentation at http://xml.apache.org/xerces-c/apiDocs/index.html
(You may also want to get a good book on programming in C++.)
--Bill