How To load XML file into iPhone project - iphone

I have an XML documment that I want to load for the iPhone, do I need to convert it to a plist first ? if so how ?
The xml document has the following code ( for 1 chapter)
<toolTipsBook>
− <chapter index="1" name="Chapter Name">
<line index="1" text="line text here"/>
<line index="2" text=" line text here "/>
<line index="3" text=" line text here "/>
<line index="4" text=" line text here "/>
<line index="5" text=" line text here "/>
<line index="6" text=" line text here "/>
<line index="7" text=" line text here "/>
</chapter>
How can I tell xcode to display chapter 1 line 1 and then leave space under that for my comment ( a seperate xml document) for chapter l line 1 directly under it.
The idea is that I'll have this control for all the chapters in the data I'm loading.
If you have a little time I'd really appreciate it if you could give some sample could to please show what you mean.
Thanks guys,

You can add the XML file into resources of your application.
You do that by dragging to resources directory in Xcode, and in popup select copy file to project.
When your application run you open the file by referring to it by it's name, read in the XML, parse it with NSXMLParser and extract required data. No need to convert to plist.
This assumes that the xml data is static and you don't indent to update and save it.

Have you looked at NSXMLParser?
It's purpose is to parse the XML into a data structure.
Then you display that data structure using whatever user interfaces you feel are appropriate (such as a UITableView).

Related

VSCode: Delete all occurences of xml tag pair including differing contents

I'm working in a kml (xml) file in VSCode. There are 267 instances of the <description></description> tags with the same contents schema but different contents. I would like a fast way to delete all of the instances of <description> including the contents instead of manually deleting each one. I'm not married to VSCode if Notepad++ or another editor will do what I'm trying to do.
Use one command/macro to delete both of these (plus 265 more)
<description><![CDATA[<center><table><tr><th colspan='2' align='center'>
<em>Attributes</em></th></tr><tr bgcolor="#E3E3F3">
<th>NAME</th>
<td>Anderson</td>
</tr><tr bgcolor="#E3E3F3">
</tr></table></center>]]>
</description>
<description><![CDATA[<center><table><tr><th colspan='2' align='center'>
<em>Attributes</em></th></tr><tr bgcolor="#E3E3F3">
<th>NAME</th>
<td>Billingsly</td>
</tr><tr bgcolor="#F00000">
</tr></table></center>]]>
</description>
Thank you, Paul
You can use this regex in vscode find/replace:
\n?<description>[\S\s\n]*?<\/description>\n?
and replace with nothing. The \n?'s at the beginning and end are there if you want to delete the lines the tags occur on as well - see how it works, you can remove those if you don't care about empty lines where your deleted content used to be.
Obviously, if you have malformed input, like unmatched <description> or </description> tags the regex won't work.

Apache FOP insert special character [duplicate]

I am maintaining a program which uses the Apache FOP for printing PDF documents. There have been a couple complaints about the Chinese characters coming up as "####". I have found an existing thread out there about this problem and done some research on my side.
http://apache-fop.1065347.n5.nabble.com/Chinese-Fonts-td10789.html
I do have the uming.tff language files installed on my system. Unlike the person in this thread, I am still getting the "####".
From this point forward, has anyone seen a work around that would allow you to print complex characters in a PDF document using Apache FOP?
Three steps must be taken for chinese characters to correctly show in a PDF file created with FOP (this is also true for all characters not available in the default font, and more generally to use a non-default font).
Let us use this simple fo example to show the warnings produced by FOP when something is wrong:
<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="one">
<fo:region-body />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="one">
<fo:flow flow-name="xsl-region-body">
<!-- a block of chinese text -->
<fo:block>博洛尼亚大学中国学生的毕业论文</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
Processing this input, FOP gives several warnings similar to this one:
org.apache.fop.events.LoggingEventListener processEvent
WARNING: Glyph "?" (0x535a) not available in font "Helvetica".
...
Without any explicit font-family indication in the FO file, FOP defaults to using Helvetica, which is one of the Base-14 fonts (fonts that are available everywhere, so there is no need to embed them).
Each font supports a set of characters, assigning a visible glyphs to them; when a font does not support a character, the above warning is produced, and the PDF shows "#" instead of the missing glyph.
Step 1: set font-family in the FO file
If the default font doesn't support the characters of our text (or we simply want to use a different font), we must use the font-family property to state the desired one.
The value of font-family is inherited, so if we want to use the same font for the whole document we can set the property on the fo:page-sequence; if we need a special font just for some paragraphs or words, we can set font-family on the relevant fo:block or fo:inline.
So, our input becomes (using a font I have as example):
<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="one">
<fo:region-body />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="one">
<fo:flow flow-name="xsl-region-body">
<!-- a block of chinese text -->
<fo:block font-family="SimSun">博洛尼亚大学中国学生的毕业论文</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
But now we get a new warning, in addition to the old ones!
org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "SimSun,normal,400" not found. Substituting with "any,normal,400".
org.apache.fop.events.LoggingEventListener processEvent
WARNING: Glyph "?" (0x535a) not available in font "Times-Roman".
...
FOP doesn't know how to map "SimSun" to a font file, so it defaults to a generic Base-14 font (Times-Roman) which does not support our chinese characters, and the PDF still shows "#".
Step 2: configure font mapping in FOP's configuration file
Inside FOP's folder, the file conf/fop.xconf is an example configuration; we can directly edit it or make a copy to start from.
The configuration file is an XML file, and we have to add the font mappings inside /fop/renderers/renderer[#mime = 'application/pdf']/fonts/ (there is a renderer section for each possible output mime type, so check you are inserting your mapping in the right one):
<?xml version="1.0"?>
<fop version="1.0">
...
<renderers>
<renderer mime="application/pdf">
...
<fonts>
<!-- specific font mapping -->
<font kerning="yes" embed-url="/Users/furini/Library/Fonts/SimSun.ttf" embedding-mode="subset">
<font-triplet name="SimSun" style="normal" weight="normal"/>
</font>
<!-- "bulk" font mapping -->
<directory>/Users/furini/Library/Fonts</directory>
</fonts>
...
</renderer>
...
</renderers>
</fop>
each font element points to a font file
each font-triplet entry identifies a combination of font-family + font-style (normal, italic, ...) + font-weight (normal, bold, ...) mapped to the font file in the parent font element
using directory elements it is also possible to automatically configure all the font files inside the indicated folders (but this takes some time if the folders contain a lot of fonts)
If we have a complete file set with specific versions of the desired font (normal, italic, bold, light, bold italic, ...) we can map each file to the precise font triplet, thus producing a very sophisticated PDF.
On the opposite end of the spectrum we can map all the triplet to the same font file, if it's all we have available: in the output all text will appear the same, even if in the FO file parts of it were marked as italic or bold.
Note that we don't need to register all possible font triplets; if one is missing, FOP will use the font registered for a "similar" one (for example, if we don't map the triplet "SimSun,italic,400" FOP will use the font mapped to "SimSun,normal,400", warning us about the font substitution).
We are not done yet, as without the next and last step nothing changes when we process our input file.
Step 3: tell FOP to use the configuration file
If we are calling FOP from the command line, we use the -c option to point to our configuration file, for example:
$ fop -c /path/to/our/fop.xconf input.fo input.pdf
From java code we can use (see also FOP's site):
fopFactory.setUserConfig(new File("/path/to/our/fop.xconf"));
Now, at last, the PDF should correctly use the desired fonts and appear as expected.
If instead FOP terminates abruptly with an error like this:
org.apache.fop.cli.Main startFOP
SEVERE: Exception org.apache.fop.apps.FOPException: Failed to resolve font with embed-url '/Users/furini/Library/Fonts/doesNotExist.ttf'
it means that FOP could not find the font file, and the font configuration needs to be checked again; typical causes are
a typo in the font url
insufficient privileges to access the font file

XSLT Stylesheet works with a vbs script, but not Perl

I have a program that is essentially a search application, and it exists in both VBScript and Perl form (I'm trying to make an executable with a GUI).
Currently the search application outputs an HTML file, and if a section of text in the HTML is longer than twelve lines then it hides anything after that and includes a clickable More... tag.
This is done in XSLT and works with VBScript.
I literally copied and pasted the stylesheet into the Perl program that I'm using and it does everything right except for the More... tag.
Is there any reason why it would be working with the VBScript but not Perl?
I'm using XML::LibXSLT in the Perl script, and here is the template that is supposed to be creating the More... tag
<xsl:template name="more">
<xsl:param name="text"/>
<xsl:param name="row-id"/>
<xsl:param name="cycle" select="1"/>
<xsl:choose>
<xsl:when test="($cycle > 12) and contains($text,'
')">
<span class="show" onclick="showID('SHOW{$row-id}');style.display = 'none';">More...</span>
<span class="hidden" id="SHOW{$row-id}">
<xsl:call-template name="highlight">
<xsl:with-param name="text" select="$text"/>
</xsl:call-template>
</span>
</xsl:when>
<xsl:when test="contains($text,'
')">
<xsl:call-template name="highlight">
<xsl:with-param name="text" select="substring-before($text,'
')"/>
</xsl:call-template>
<xsl:text>
</xsl:text>
<xsl:call-template name="more">
<xsl:with-param name="text" select="substring-after($text,'
')"/>
<xsl:with-param name="row-id" select="$row-id"/>
<xsl:with-param name="cycle" select="$cycle + 1"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="highlight">
<xsl:with-param name="text" select="$text"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
I believe the problem is that your XSLT is searching the text for CR characters - 
.
Windows files use the CR LF character pair to terminate each line of text, and a version of Perl running on a Windows system will strip the CR to leave just the LF.
This provides an API compatible with Linux-like systems, which use just LF in the first place, but means your XSLT stylesheet doesn't find any CR characters when it looks for them.
I suggest you change your stylesheet to search instead for LF characters, which will be present at the end of every line regardless of the file's origin, and will be seen by both Perl and VBScript.
I think character codes are best expressed in hex, so you would change '
 to '
throughout your XSLT code.
Note
By making this change your strings will be left with a trailing CR after you use substring-before($text, '
'). You can either leave this in place — I don't think it will do any harm as it won't be rendered by a browser — or you can remove from the string that you pass to the more template when you call it
<xsl:call-template name="more">
<xsl:with-parameter name="text" value="translate($text, '
', '')"/>
...
</xsl:call-template>
That would leave the template with a clean string to process, containing no CR characters.

Sitecore: Valid item names

How do I expand the list of valid characters in item names, to include æøåÆØÅ?
As per default the valid characters seems to be defined by this rule in web.config:
<setting name="ItemNameValidation" value="^[\w\*\$][\w\s\-\$]*(\(\d{1,}\)){0,1}$" />
changing the regex to :
<setting name="ItemNameValidation" value="^[\wæøåÆØÅ\*\$][\wæøåÆØÅ\s\-\$]*(\(\d{1,}\)){0,1}$" />
Should in theory allow the characters, but that just "kills" the sitecore.
Edit:
A regex that allows dots, are working perfectly like this:
<setting name="ItemNameValidation" value="^[\w\*\$][\w\.\s\-\$]*(\(\d{1,}\)){0,1}$" />
So I am allowed to change some aspects of it, just not for the æøå characters?!?!?
Note:
- Using æøå in item names is for some reason possible from the "Page Editor", when creating and saving new content items, but it is not possible to do the same from the "Content Editor"!
- We are using SC v6.6.0 (rev. 120918).
Cause of error was not saving the file as UTF-8
Make sure your config file is saved as "UTF-8"
A bit late, but adding as an answer :)
Cause of error was not saving the file as UTF-8

How to display umlauts in chm Table of Contents?

I'm creating the german version of a chm help file. My problem is in Table of Contents umlauts are not displayed. I assume it is because of code page. The hhc file is ANSI. Converting it to Unicode doesn't help - it displays different, but still wrong, characters.
The file "Table of Contents.hhc" starts with
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML>
<HEAD>
<meta name="GENERATOR" content="Microsoft® HTML Help Workshop 4.1">
<!-- Sitemap 1.0 -->
</HEAD><BODY>
<OBJECT type="text/site properties">
<param name="ImageType" value="Folder">
</OBJECT>
<UL>
<LI> <OBJECT type="text/sitemap">
<param name="Name" value="ÜÜÜÜÜÜÜÜÜÜÜÜÜÜ Uberblick">
<param name="Local" value="overview.htm">
<param name="URL" value="overview.htm">
</OBJECT>
</UL>
</BODY></HTML>
Make sure the "Language" setting in the "Options" section of the project file supports the character you want. Since you are on a Russian system, the default is probably Russian. Change it to German, for instance.
The engine rendering the chm is Unicode, only the compiler is ansi.
Try escaping them? http://www.w3schools.com/tags/ref_entities.asp
or the charset encoding:http://www.w3.org/TR/html4/charset.html#h-5.2.2
Actually, you don't need UTF-8 for CHM files because CHM doesn't support UTF-8 or Unicode. CHM is an ancient format that Microsoft has not really changed since Windows 98, and it has a number of quirks and restrictions like this
Read for more detail...
https://helpman.it-authoring.com/viewtopic.php?t=9294
https://blogs.msdn.microsoft.com/sandcastle/2007/09/29/chm-localization-and-unicode-issues-dbcsfix-exe/