Extract HTML from CDATA node in iPhone - objective-c

<item>
<data>
<![CDATA[
<p>Test</p>
<p><strong>Hi!</strong><br />Hello.</p>
]]>
</data>
</item>
Using TouchXML/NSXMLParser How can i extract only the HTML part into a string/appropriate data format so that I can display it in a UIWebView?
It's definitely possible: http://code.google.com/p/touchcode/issues/detail?id=36&can=1&q=cdata

TouchXML will parse it automatically. If you retrieve the stringValue of the CXMLElement you will get the full "raw" html back, properly formed.

Related

Error while creating new data file in HP-Exstream

I am trying to create a data file for my application with XML as input and map it to my HP Exstream variables. But when I am trying to save the file it is giving me error "No customer-level tag specified! Engine will not process.". I am not sure how to resolve this error. There is no customer level information I want in my input. Can anyone explain what is this error and how to resolve it?
What HP Exstream is telling you is that you have not defined a tag that will allow Exstream to know when a customer begins and ends. This does not have to be a tag that says <customer-level>, but rather the tag you are using in the XML to determine where a customer begins and ends.
When you are using an XML file as input, you may be dealing with multiple customers take this for example:
<item>
<address>
<line>a</line>
<line>b</line>
</address>
<body>Hello World</body>
</item>
<item>
<address>
<line>c</line>
<line>d</line>
</address>
<body>Hello Universe</body>
</item>
I would be using the <item> tag to tell HP Exstream where my customer begins and ends.
You can choose the customer tag in the properties of the tags.

Build New XML From Stored XML Value

We store rather large XML blobs (in an column of XML type) and I'm pursuing a skunkworks project to try to build up a subset of the XML on the fly when needed.
Let's say I have this XML blob stored in our database table in a given column:
<root>
<header>
<id>1</id>
<name id="foo">Name</name>
</header>
<body>
<items>
<addItem>
<val>1</val>
</addItem>
<observeItem>
<val>2</val>
</observeItem>
</items>
</body>
</root>
What I want to get out is this is to basically recreate the above document structure but only include one of the items children, so for example:
<root>
<header>
<id>1</id>
<name id="foo">Name</name>
</header>
<body>
<items>
<observeItem>
<val>2</val>
</observeItem>
</items>
</body>
</root>
If I were interested in just the observeItem record (the items element can have any number of children, but I'll only ever be interested in a single one of them).
I know I can do something like SELECT #XML.query('//items/child::*[2]') to get just a given child item, but how would I build up the full original document in a query with just one of those children?
I've come up with a solution, but I'm not entirely pleased with it:
DECLARE #XML XML = '
<root>
<header>
<id>1</id>
<name id="foo">Name</name>
</header>
<body>
<items>
<addItem>
<val>1</val>
</addItem>
<observeItem>
<val>2</val>
</observeItem>
</items>
</body>
</root>'
DECLARE #NthChild INT = 2
SELECT
#XML.query('//header'),
#XML.query('//items/child::*[sql:variable("#NthChild")]') AS 'items'
FOR XML PATH('root')
I don't like having to specify the root explicitly nor the items, but I think this approach could get me by.

How to keep cts:highlight from matching inside XML tags?

I am trying to search some content and highlight the search strings present in the XML content(like google) in MarkLogic using REST API. The problem is when I am including "ME" in the search-string,it's highlighting the 'i' tags(html Italic tags) along with the "Me" in the content. I have created a document with some elements and running a word-query on the document.
For example XML content:
<resources>
<title> some data from me</title>
<desc> more data <i> from </i> somewhere by me </desc>
</resources>
I have created a document with root node 'resources' and child elements 'title' and 'desc' and searching the search strings within the document using word-query.
Now when i search for "some me" ,its retrieving the content like
<resources>
<title> <<span class="highlight">some</span> data from <<span class="highlight">me</span>
</title>
<desc> more data <<span class="highlight">i</span>> from <<span class="highlight">i</span>> somewhere by <span class="highlight">me</span> </desc>
</resources>
Url:
localhost:9000/v1/search?q=some me&collection=Data&start=0&pageLength=10&options=Transformation&format=json
I am using cts:highlight for highlighting,some thing like :
cts:highlight($final-result, $query, fn:concat('<span class="highlight">',$cts:text,'</span>')), $custom-config)
Any ideas on why the html elements are highlighted here?
Thanks in Advance.
You probably inserted your document in text format, not xml format. I can reproduce your issue by inserting in text format:
xdmp:document-insert("test.xml", text {"<resources>
<title> some data from me</title>
<desc> more data <i> from </i> somewhere by me </desc>
</resources>"})
then running a cts:highlight on that document:
cts:highlight(doc("test.xml"), cts:parse("some me"), concat('<span class="highlight">', $cts:text, '</span>'))
But if I re-insert the document as XML:
xdmp:document-insert("test.xml", <resources>
<title> some data from me</title>
<desc> more data <i> from </i> somewhere by me </desc>
</resources>)
then the same cts:highlight works better:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<title> <span class="highlight">some</span> data from <span class="highlight">me</span></title>
<desc> more data <i> from </i> somewhere by <span class="highlight">me</span> </desc>
</resources>
If I add the suggestion from #ehennum and #mholstege and instead run this cts:highlight:
cts:highlight(doc("test.xml"), cts:parse("some me"), <span class="highlight">{$cts:text}</span>)
then I get what I would guess you're looking for:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<title> <span class="highlight">some</span> data from <span class="highlight">me</span></title>
<desc> more data <i> from </i> somewhere by <span class="highlight">me</span> </desc>
</resources>
What version of MarkLogic is this?
Can you include a more complete example? What is $custom-config for example? And how is the REST call results linked to cts:highlight? For markup to be highlighted in this way, that results would have to be text rather than XML.
By the way, the third argument to cts:highlight is an expression -- if you want to create markup, just use constructors there, not string concatenation:
cts:highlight($final-result, $query, <span class="highlight">{$cts:text}</span>, $custom-config)
Try supplying the tags in the cts:hightlight() expression as nodes instead of a string.
That is, instead of
fn:concat('<span class="highlight">',$cts:text,'</span>')
try
<span class="highlight">{$cts:text}</span>
For more information, see the first example in:
http://docs.marklogic.com/cts:highlight?q=cts:highlight
Hoping that helps,

Mule ESB: Issue w/ XML generated from MapsToXML input to DataMapper

I have a JDBC outbound endpoint that after performing Map To XML transformation, gives out XML in the following format:
<?xml version="1.0" encoding="UTF-8"?>
<table>
<record>
<field name="DESTINATION" type="java.lang.String">SFO</field>
<field name="PRICE" type="java.lang.String">500</field>
<field name="ID" type="java.lang.Integer">2</field>
</record>
</table>
The problem is that when I try to generate the schema for this XML for use in the datamapper , the fields that are generated from this are not usable (it only shows field , In the mapping file I get this message when I try to hover over it :
'The attribute cannot be dragged since it does not belong to 'Current Element Mapping'
How do I use my XML so that I can map those fields to either another CSV, database or some other entity?
Why not trying to map (via DataMapper) Map object directly to CSV or anything you'd like ? If you need this intermediary XML format, you can also use DataMapper for the initial Map->XML mapping and configure the way you want it to look like (instead using MapsToXML).

Parsing using NSXMLParser

I am being returned some XML from a web service. Basically, the xml looks like this:
<response>
<data>
More XML here but the it's escaped by XML entities
</data>
</response>
so, as you can see, I have xml that is valid, but the stuff inside data tag is escaped with XML entities. what's the best (most efficient) way for me to feed this into the parser?
What I am doing right now is, when I get the data from web service, I convert it into NSString....then replace the "XML escaped entities" with real ones.....then convert it back into NSData...then feed it into the parser. This doesn't seem like a very good solution so I was wondering if there's a better way to do it?
Thanks.
Alright, here's the xml that I am getting:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><ActivityId CorrelationId="d39007b5-ee69-41c7-a61d-831b456f9ea3" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">aa88d1cd-253c-48d1-abeb-62a880bea806</ActivityId></s:Header><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><LoginResponse xmlns="http://MSS"><LoginResult><LoginInformation>
<User>
<UserID>612</UserID>
<UserName>Demo User</UserName>
<Email>mssdev#mss-mail.com</Email>
<CompanyID>17034</CompanyID>
<CompanyName>PlanET Demonstration Agency</CompanyName>
</User>
</LoginInformation></LoginResult></LoginResponse></s:Body></s:Envelope>
As you can see, everything in is escaped.
That's kind of horrifying. Why don't you just take the contents of that tag (e.g. the data with the entities) and just pass that through another NSXMLParser? The first parser will have decoded the entities, and the second parser will be presented with the decoded version of the contents of that tag.