Jump to content

Recommended Posts

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

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

*******************************/

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.. 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.