0

I would like to insert a break tag between two words in product name below,

<product productName="Portable<br> Audio Recorder" productID="ABC" thumbPath="images/a1.jpg">

below is the complete XML code,

<category categoryName="New Arrival" categoryID="new-arrival">

    <product productName="Portable<br> Audio Recorder" productID="ABC" thumbPath="images/a1.jpg">

        <details>

            <![CDATA[

            <p><img src="images/a.jpg" width="100%"></p>

            ]]>

    </details>

    </product>

</category>

I have tried,

&#xA; \ <br> \ <![CDATA[<br/>]]> \ ("<br />") \ 

But still not working.. Please help me..

Adi
  • 25
  • 1
  • 9
  • [Have you tried `\n`](http://stackoverflow.com/a/31683548/1559401)? – rbaleksandar Dec 08 '16 at 06:29
  • yest but still not working.. – Adi Dec 08 '16 at 06:30
  • I find it weird that ` ` doesn't work. According to the standard ([see here](https://www.w3.org/TR/REC-xml/#NT-AttValue)) it should work. Tags are obviously not allowed. – rbaleksandar Dec 08 '16 at 06:34
  • Where you ultimately put the data? If it is html, use `
    `. In the attribute it should be written as `<br/>`. If it is a text (.txt file), use `\r`, `\n` or both (the requirement for Windows). In the attribute should be written ` ` or ` ` or both.
    – Alexander Petrov Dec 08 '16 at 10:24

2 Answers2

1

You cannot put a tag of any sort in the place you want, because that's inside an attribute value. Attribute values do not contain tags, period. No matter what you put there, by definition, it is not a tag.

You can place any character you like, however. For example, you can insert a newline character via an entity reference. For example:

<product productName="Portable&#x0a; Audio Recorder" productID="ABC" thumbPath="images/a1.jpg">

Update:

You can also place characters into an attribute value that would constitute a tag elsewhere, but you must present the < via an entity reference:

<product productName="Portable&lt;br> Audio Recorder" productID="ABC" thumbPath="images/a1.jpg">

How that attribute value is interpreted by software that processes your XML is an altogether different question. Generally speaking, I would expect software that transforms the XML to take care to escape the text as necessary to preserve its textual interpretation in the destination context, but it's possible that yours does not do that. Consult your documentation.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • Yes, tags are not allowed but you didn't read the end of the question. The OP did trie ` ` and it didn't work. – rbaleksandar Dec 08 '16 at 06:33
  • @rbaleksandar, the first paragraph is a complete answer to the question posed, the end of the question notwithstanding. The second paragraph is possibly extraneous information, but inasmuch as the OP does not present exactly what he tried along those lines, it may provide what he actually wants after all. – John Bollinger Dec 08 '16 at 06:37
  • Yes, I have tried still not working.. I can share you my link also, http://teleshopltd.com/addto-new/new.html Just cause of product name, alignment gets messed up.. so if i add another product, then the alignment gets disturbed.. So im planning to give break to single line product name.. so tht it will look proper.. – Adi Dec 08 '16 at 06:39
  • @Adi, I have updated my answer to speak more directly to what you seem to want, but the bottom line is essentially the same as far as the question you've posed *about XML*. If you have a question about the software by which your XML is rendered at the site you've linked, then that's a completely different thing. – John Bollinger Dec 08 '16 at 06:53
  • @JohnBollinger Again - did you read the whole post? I will quote the OP: "I have tried, \
    \ <![CDATA[
    ]]> \ ("
    ") \ but still not working" I would say the OP posted exactly what he has tried so far. As for the why there needs to be a break inside the string - that's another topic omho.
    – rbaleksandar Dec 08 '16 at 06:54
  • @Adi, that is exactly what I predicted, is it not? If there is a way to achieve the presentation you want then that's first and foremost a function of the software you're using to generate pages. It is entirely possible that that software provides no way to do so. In any event, I've already covered pretty much everything there is to say about the question as posed and with respect to XML in general. – John Bollinger Dec 08 '16 at 07:03
  • thanks @JohnBollinger but is there any way so that i can show products in a proper alignment.. it shouldn't look up and down? – Adi Dec 08 '16 at 07:08
  • 1
    @Adi, I see the problem you are trying to solve. As I already said, if there is a solution at all, it is primarily a function of your page-generation software. That would be a completely different question, and you are highly unlikely to get an answer to such a question here unless you can present a [mcve]. – John Bollinger Dec 08 '16 at 07:18
0

Everything except <, &, and your delimiter (' or ") are fine. For your reference

https://www.w3.org/TR/REC-xml/#NT-AttValue

Vishal T
  • 82
  • 6