Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read XML file/DOM to extract element value 1

Status
Not open for further replies.

raypru

Technical User
Apr 9, 2002
26
GB
Does anyone have examples using SAX that will enable me to extract the values myType and myContent from the TYPE and CONTENT tags using the XML example below. The XML could be held in a file, string or DOM:

<MESSAGE>
<TYPE>myType</TYPE>
<CONTENT>myContent</CONTENT>
</MESSAGE>

 
Thanks for the link to the SAX tutorial, it helped me a great deal.

Just one further question I am trying to parse the following using the SAX example from the link and everything is written out to a file except the equals(=) character both before "text/css" and "#F5F5DC". Any ideas why this would occur:

<style type="text/css">h3 {font-size: 18; font-family: arial; color: "#0000ff"}h1 {letter-spacing: 8px; font-size: 200%; color: "#ff6347"; font-family: arial;}h2 {font-size: 120%; font-family: arial; color: "#6600ff";}err {font-style: bold;font-size: 18; font-family: arial; color: white}norm {font-style: bold;font-size: 16;font-family: arial; color: black}</style></head><body bgcolor="#F5F5DC"/>

 
Yes, because "type" is an attribute of "style" and the syntax of these attributes is "attribute=value" - so the parser will automatically strip them out. You will have to add them explictly is you need the "=" sign ...

Good Luck !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top