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 Tony Wuebben <wu...@lexis-nexis.com> on 2000/07/05 21:51:24 UTC

Entity Help

I am having trouble getting entity-reference(s) to show up in the DOM
tree. If my documnet looks like the following:

	<?xml version="1.0" encoding="utf-8"?>
	<!DOCTYPE doc [ 
	        <!ENTITY sect "SECTION" >
	        <!ELEMENT doc (child1|child2)*>
	        <!ELEMENT child1 (#PCDATA)*>
  	      <!ELEMENT child2 (#PCDATA)*>
	]>
 	<doc><child1>AT&amp;T</child1><child2>This is a &sect;
end</child2></doc>


When I set ExpandEntityReferences = to 'true' I get an DOM_DOMException
when I parse the document (error code=10 INUSE_ATTRIBUTE_ERR). The tree
at the exception time is how I expect it to look but an exception is
thrown. Tree looks like the following:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE doc[ 
        <!ENTITY sect>
        <!ELEMENT doc (child1|child2)*>
        <!ELEMENT child1 (#PCDATA)*>
        <!ELEMENT child2 (#PCDATA)*>
]><doc><child1>AT&T</child1><child2>This is a &sect;</child2></doc>


1)What I need to do is read in an entity reference and output the same
entity reference. I can't get the DOMParser to create entity reference
for the 5 predefined entities or my created entities (throws exception
on mine).

2) In the DOCTYPE I can't get the ENTITY replacement value to be created
correctly, My example "SECTION". 

Any help would greatly be appreciated. 

Tony Wuebben
Lexis-Nexis

Reading Entity values?

Posted by Thomas Norton <to...@ndtechnologies.com>.
Hi,
I'm having a difficult time parsing external entity values using the DOM
parser.
I hope someone can set me straight.

Say I have something in the DTD like:

            <!ENTITY % myEntity "(one | two | three)">

When parsing the xml file which uses this DTD, my goal is to:
    - access the 'myEntity' entity
    - read all of it's possible values.   (In this case - 'one', 'two',
'three')

I can actually see each of the entity names, but not any other information
associated with them.

----------------
The code fragment:

       parser.setDoValidation(true);
        parser.setExpandEntityReferences (true);
        parser.parse(theXmlFile);

        DOM_Document doc = parser.getDocument();
        DOM_DocumentType docType =  doc.getDoctype();
        DOM_NamedNodeMap nodeMap= docType.getEntities();
-----------------

At this point nodeMap has all the entities.  I can iterate through the
nodeMap
and read the node names.( like 'myEntity').

Any attempt to read the entity children
        - nodeMap.item(i).getChildNodes()

or entity attributes
        - nodeMap.item(i).getAttributes()

 returns a zero-length node.  Am I missing something?

Thanks
 - Tom