Jump to content

Object Required, Why?


johnnyg24
 Share

Recommended Posts

I keep getting an "Object Required" Error when the following function is executed. It worked fine until I added another Element . When I take it out it works fine again. I can't figure out why it does this. Can anyone take a look and tell me if I have done something wrong. The element in question is indicated below. Thanks.

var db = new Array();	  	  function getOneSku(xDoc, i) {		 var oneRecord = new Object();		 var oneElem = xDoc.getElementsByTagName("sku")[i];		 oneRecord.idNum = oneElem.getElementsByTagName("idNum")[0].firstChild.data;		 oneRecord.desc = oneElem.getElementsByTagName("desc")[0].firstChild.data;		 // the next line is the one I added		 oneRecord.pName = oneElem.getElementsByTagName("pName")[0].firstChild.data;		 oneRecord.construction = oneElem.getElementsByTagName("construction")[0].firstChild.data;		 oneRecord.constructionTXT = oneElem.getElementsByTagName("constructionTXT")[0].firstChild.data;		 oneRecord.pStyle = oneElem.getElementsByTagName("pStyle")[0].firstChild.data;		 oneRecord.pStyleTXT = oneElem.getElementsByTagName("pStyleTXT")[0].firstChild.data;		 oneRecord.pClass = oneElem.getElementsByTagName("pClass")[0].firstChild.data;		 oneRecord.pClassTXT = oneElem.getElementsByTagName("pClassTXT")[0].firstChild.data;		 oneRecord.confCode = oneElem.getElementsByTagName("confCode")[0].firstChild.data;		 		 oneRecord.pColorCode = oneElem.getElementsByTagName("pColorCode")[0].firstChild.data;		 oneRecord.pColorCodeTXT = oneElem.getElementsByTagName("pColorCodeTXT")[0].firstChild.data;		 oneRecord.book = oneElem.getElementsByTagName("book")[0].firstChild.data;		 oneRecord.bookTXT = oneElem.getElementsByTagName("bookTXT")[0].firstChild.data;		 oneRecord.skuImg = oneElem.getElementsByTagName("skuImg")[0].firstChild.data;		 return oneRecord;		 }

XML it is pulling from:

<skus>	<sku>	<idNum>JOPL-1</idNum>		<desc>Joplin 1 Orange</desc>	<pName>Joplin</pName> 		<construction>16</construction> 		<constructionTXT>Chenille</constructionTXT>		<pStyle>03</pStyle>		<pStyleTXT>Tarditional Stripe</pStyleTXT>		<pClass>1</pClass>		<pClassTXT>Upholstery</pClassTXT>		<confCode>Exclusive</confCode>		<country>USA</country>		<rr>yes</rr>		<pWidth>54"</pWidth>		<vRepeat>0"</vRepeat>	<hRepeat>6.375"</hRepeat>		<fiber>54% Spun Viscose, 36% Cotton, 10% Polyester</fiber>		<finish>Teflon</finish>		<pTest>W15</pTest>		<cleanCode>DCO</cleanCode>		<wPrice>$20.95</wPrice>		<rPrice>$42.00</rPrice>		<pColorCode>100</pColorCode>		<pColorCodeTXT>Marine</pColorCodeTXT>		<book>1032</book>		<bookTXT>Art of Color - Aqua</bookTXT>		<skuImg>../Images/JOPL-1.jpg</skuImg>		</sku>	<sku>	<idNum>JOPL-2</idNum>	<desc>Joplin 2 Pink</desc>	<pName>Joplin</pName> 	<construction>16</construction> 	<constructionTXT>Chenille</constructionTXT>	<pStyle>03</pStyle>	<pStyleTXT>Tarditional Stripe</pStyleTXT>	<pClass>1</pClass>	<pClassTXT>Upholstery</pClassTXT>	<confCode>Exclusive</confCode>	<country>USA</country>	<rr>yes</rr>	<pWidth>54"</pWidth>	<vRepeat>0"</vRepeat>	<hRepeat>6.375"</hRepeat>	<fiber>54% Spun Viscose, 36% Cotton, 10% Polyester</fiber>	<finish>Teflon</finish>	<pTest>W15</pTest>	<cleanCode>DCO</cleanCode>	<wPrice>$20.95</wPrice>	<rPrice>$42.00</rPrice>	<pColorCode>200</pColorCode>	<pColorCodeTXT>Pink</pColorCodeTXT>	<book>1033</book>	<bookTXT>Art of Color - Red</bookTXT>	<skuImg>../Images/JOPL-2.jpg</skuImg>	</sku>		<sku>	<idNum>JOPL-3</idNum>	<desc>Joplin 3 White</desc>	<pName>Joplin</pName> 	<construction>16</construction> 	<constructionTXT>Chenille</constructionTXT>	<pStyle>03</pStyle>	<pStyleTXT>Tarditional Stripe</pStyleTXT>	<pClass>1</pClass>	<pClassTXT>Upholstery</pClassTXT>	<confCode>Exclusive</confCode>	<country>USA</country>	<rr>yes</rr>	<pWidth>54"</pWidth>	<vRepeat>0"</vRepeat>	<hRepeat>6.375"</hRepeat>	<fiber>54% Spun Viscose, 36% Cotton, 10% Polyester</fiber>	<finish>Teflon</finish>	<pTest>W15</pTest>	<cleanCode>DCO</cleanCode>	<wPrice>$20.95</wPrice>	<rPrice>$42.00</rPrice>	<pColorCode>100</pColorCode>	<pColorCodeTXT>White</pColorCodeTXT>	<book>1033</book>	<bookTXT>Art of Color - Red</bookTXT>	<skuImg>../Images/JOPL-3.jpg</skuImg>	</sku>	<sku>	<idNum>JOPL-4</idNum>	<desc>Joplin 4 Black</desc>	<pName>Joplin</pName>  	<construction>16</construction> 	<constructionTXT>Chenille</constructionTXT>	<pStyle>03</pStyle>	<pStyleTXT>Tarditional Stripe</pStyleTXT>	<pClass>1</pClass>	<pClassTXT>Upholstery</pClassTXT>	<confCode>Exclusive</confCode>	<country>USA</country>	<rr>yes</rr>	<pWidth>54"</pWidth>	<vRepeat>0"</vRepeat>	<hRepeat>6.375"</hRepeat>	<fiber>54% Spun Viscose, 36% Cotton, 10% Polyester</fiber>	<finish>Teflon</finish>	<pTest>W15</pTest>	<cleanCode>DCO</cleanCode>	<wPrice>$20.95</wPrice>	<rPrice>$42.00</rPrice>	<pColorCode>400</pColorCode>	<pColorCodeTXT>Black</pColorCodeTXT>	<book>1032</book>	<bookTXT>Art of Color - Aqua</bookTXT>	<skuImg>../Images/JOPL-4.jpg</skuImg>	</sku></skus

>

Link to comment
Share on other sites

It looks fine to me. Use Firebug to print the different parts of the expression and find out what's going on.console.log(oneElem.getElementsByTagName("pName"));console.log(oneElem.getElementsByTagName("pName")[0]);console.log(oneElem.getElementsByTagName("pName")[0].firstChild);console.log(oneElem.getElementsByTagName("pName")[0].firstChild.data);

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...