kutchbhi Posted October 16, 2013 Share Posted October 16, 2013 I am looking at an xml that has the greater than sign inside the attribute value. <CATEGORY id='163' name='Toys > Other '></CATEGORY> My job is to create a similar xml where the > sign exists inside the node's attribute value ? is this possible ? how ? I tried this: $catName = htmlspecialchars_decode(str_replace('-', '>',$CategoryName )) ; but it just encoded the > into > . Thanks Link to comment https://forums.phpfreaks.com/topic/283018-html-entities-inside-attribute-values-of-an-xml/ Share on other sites More sharing options...
Barand Posted October 16, 2013 Share Posted October 16, 2013 Are you sure it's an issue? $str = <<<XML <A> <Category name='Toys > Other'> <Item>item 1</Item> <Item>item 2</Item> <Item>item 3</Item> </Category> <Category name='Games > Other'> <Item>item 4</Item> <Item>item 5</Item> <Item>item 6</Item> </Category> </A> XML; $xml = simplexml_load_string($str); foreach ($xml->Category as $cat) { echo "{$cat['name']}<br>"; foreach ($cat->Item as $i) { echo " • $i<br>"; } } /********** OUTPUT ********** Toys > Other • item 1 • item 2 • item 3 Games > Other • item 4 • item 5 • item 6 *******************************/ Link to comment https://forums.phpfreaks.com/topic/283018-html-entities-inside-attribute-values-of-an-xml/#findComment-1454150 Share on other sites More sharing options...
kutchbhi Posted October 17, 2013 Author Share Posted October 17, 2013 When I do like this $category = $dom->createElement('CATEGORY') ; $catName = htmlspecialchars_decode(str_replace('-', '>',$CategoryName )) ; $category->setAttribute('name', $catName ); I get a > instead of a > . am I doing something wrong ? also right now I am just using a str_replace on the whole file that works..but not sure if its ok.. Link to comment https://forums.phpfreaks.com/topic/283018-html-entities-inside-attribute-values-of-an-xml/#findComment-1454295 Share on other sites More sharing options...
Ch0cu3r Posted October 17, 2013 Share Posted October 17, 2013 Maybe something somewhere else is converting the > to > I think this maybe the setAttribute that is causing it. > is the html entity value of > Link to comment https://forums.phpfreaks.com/topic/283018-html-entities-inside-attribute-values-of-an-xml/#findComment-1454306 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.