Objective C: Parse malformed XML - iphone

I'm writing an iPhone app that downloads data from the Flickr API. At the moment there seems to be no way to limit how many comments it downloads, and although I'd like to get maybe 8 or 10, it sometimes sends me hundreds. I have subclassed ASIHTTPRequest so that it will only download a set amount of bytes (for example, it will stop downloading after receiving 1024 bytes of comment data).
Now, the information I'd like to parse is all there (the comment data contains things like a user id, the text, etc.). However, since it is cut off before the end, the XML is malformed, and my current solution (using ObjectiveFlickr's XML parser) is unable to parse the XML. Is there a way to handle badly formed XML, a la the way old web browsers handled HTML, and only extract the data that is well-formed?
Here is some sample data:
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<comments photo_id="5692627867">
<comment id="49862655-5692627867-72157626659891768" author="29114051#N05" authorname="eαse*" iconserver="4046" iconfarm="5" datecreate="1304689286" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626659891768">lovely lovely lovelyyyyy!!! ♥♥♥♥♥♥♥♥♥</comment>
<comment id="49862655-5692627867-72157626535581359" author="49946698#N06" authorname="RandomPics Art" iconserver="4017" iconfarm="5" datecreate="1304692593" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626535581359">nice! like soft colors and tones!</comment>
<comment id="49862655-5692627867-72157626660240896" author="49907977#N06" authorname="kiki_chi" iconserver="4014" iconfarm="5" datecreate="1304693051" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626660240896">&gt;eαse*
&gt;RandomPics Art
Thank you:) :) :)</comment>
<comment id="49862655-5692627867-72157626660761230" author="41717031#N08" authorname="petia.bourova" iconserver="4082" iconfarm="5" datecreate="1304698244" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626660761230">Thank you!Very nice photo!I like The coulers very,very much!!!</comment>
<comment id="49862655-5692627867-72157626661258700" author="31540474#N08" authorname="Leentje32" iconserver="4067" iconfarm="5" datecreate="1304703576" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626661258700">Aww so lovely!! Beautiful capture.</comment>
<comment id="49862655-5692627867-72157626662413410" author="61373986#N06" authorname="My NIKON And Me" iconserver="5310" iconfarm="6" datecreate="1304716098" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626662413410">lovely image!!!</comment>
<comment id="49862655-5692627867-72157626663408864" author="7652657#N02" authorname="Majlee" iconserver="3130" iconfarm="4" datecreate="1304728344" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626663408864">This is just adorable !</comment>
<comment id="49862655-5692627867-72157626663519092" author="15613254#N05" authorname="mr_jyoti" iconserver="4011" iconfarm="5" datecreate="1304729940" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626663519092">Cool shot. Nice bokey.</comment>
<comment id="49862655-5692627867-72157626663642456" author="16327396#N03" authorname="my beanie hat rocks" iconserver="2550" iconfarm="3" datecreate="1304731810" permalink="http://www.flickr.com/photos/kikicchi/5692627867/#comment72157626663642456">Maybe she could cheer this fella up!!
<a href="http://www.flickr.com/photos/weasteman/5652855802/in/photostream">www.flickr.com/photos/weasteman/5652855802/in/photostream</a>
=D</comment>

I am not sure about the exact XML format, but it looks simple. In such case you can try to figure out last tag in the data and add the missing closing tags manually. It should not be more than a simple string search & replace.

Related

Mirth -> HL7 into XML conversion Ques

I'm new to the Mirth Connect When I tried to convert HL7 into XML I 'm struggling.Suppose my HL7 messages have repeat segments like ORC in ORM Messages how to iterate that.
below is my code:
tmp['Messages']['orderList']['order'][count]['provider']=msg['ORC'][count]['ORC.10']['ORC.10.1'].toString();
but it is throwing an error:
`TypeError: Cannot read property "provider"` from undefined.
please help me to proceed further.
It's failing because your count is higher than the number of elements returned by tmp['Messages']['orderList']['order'], so it is returning undefined. The short answer is that you need to add another order node to tmp['Messages']['orderList'] before you can access it. It's hard to say how best to do that without seeing more of your code, requirements, outbound template, etc... Most frequently I build the node first, and then use appendChild to add it.
A simple example would be:
var tmp = <xml>
<Messages>
<orderList />
</Messages>
</xml>;
var prov = 12345;
var nextOrder = <order>
<provider>{prov}</provider>
</order>;
tmp.Messages.orderList.appendChild(nextOrder);
After which, tmp will look like:
<xml>
<Messages>
<orderList>
<order>
<provider>12345</provider>
</order>
</orderList>
</Messages>
</xml>
The technology you are using to work with xml is called e4x, and it's running on the Mozilla Rhino Javascript engine. Here are a couple resources that might help you.
https://web.archive.org/web/20181120184304/https://wso2.com/project/mashup/0.2/docs/e4xquickstart.html
https://developer.mozilla.org/en-US/docs/Archive/Web/E4X/Processing_XML_with_E4X

How to import this dita 1.3 xml?

Could somebody help poor developer with upgrading to Dita 1.3 :)
I need to make dita-ot work with newer version of xml's I was given (example below). I need to adjust something in the library but I don't have any clue where to start. I've replaced the problematic bit just for example - //FOOBAR/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE concept PUBLIC "-//FOOBAR//DTD DITA Concept//EN" "file:///D:/InfoShare/Web/Author/ASP/DocTypes/dita-sdl/1.3/dtd/technicalContent/dtd/sdlConcept.dtd">
<?ish ishref="GUID-874B737D-F63A-48C3-887A-571C38D5ED5A" version="1" lang="en-us"?>
<concept xml:lang="en-us" id="xs_help_me_contextually_please" rev="for Desktop" product="Foobar product">
<title id="GUID-F92ED443-BE97-44C7-AB36-726B2A76ECF9">New DITA declaration topic without any new elements</title>
<shortdesc id="GUID-8D7A677D-6782-4A65-96B4-F7F4B3CB5CCD">
<ph>Short description of the topic.</ph>
</shortdesc>
<prolog>
<metadata>
<category>
Content area
<keyword>Templates</keyword>
</category>
<keywords>
<indexterm id="GUID-32379B47-E4F9-4E00-A8A7-383584241D88">indexterm</indexterm>
</keywords>
</metadata>
</prolog>
<conbody>
<p id="GUID-A2466389-DC06-4052-A0EE-8684F3C3D7D3">
<ph>Text here.</ph>
</p>
</conbody>
</concept>
If I change FOOBAR TO OASIS, then it seems to work - at least it does not give any error. The
command that I'm running is:
dita -i=/app/dita/in/foobar.ditamap -f=xhtml -o=/app/dita/out
The error it gives:
[gen-list] [DOTJ079E][ERROR] File 'file:/app/dita/in/xs_help_me_contextually_please.xml' could not be loaded. Ensure that grammar files for this document type are referenced and installed properly. Cannot load file: /D:/InfoShare/Web/Author/ASP/DocTypes/dita-sdl/1.3/dtd/technicalContent/dtd/sdlConcept.dtd (No such file or directory)
[move-meta] I/O error reported by XML parser processing file:/tmp/temp20191106165059386/in/xs_help_me_contextually_please.xml: /tmp/temp20191106165059386/in/xs_help_me_contextually_please.xml (No such file or directory)
[move-meta] file:/app/dita/in/foobar.ditamap:3:327: [DOTX026W][WARN]: Unable to retrieve linktext from target: 'xs_help_me_contextually_please.xml'. Using navigation title as fallback.
Also I should add the technicalContent/dtd/sdlConcept.dtd (that I was also given) somewhere in the library but not sure where. Tried to put it in plugins/org.oasis-open.dita.v1_3 and thought it works but when removing the file and having //OAOSIS/ in the source xml, then it didn't give out any error either.
How can it all work if the path is file:///D:/InfoShare/Web/Author/ASP/Doc... that does not exist in the system where the import happens (Docker container). Is it just informational?
Very confused of all of this.
Thank you in advance!
It's hard to help you given what you have provided, but I can add some clarifying information:
You are working with DITA source that either is (or has been stored) in the SDL CCMS. Depending on the age of the SDL product it has different names: Trisoft, SDL Live Content, SDL Tridion Docs.
DITA 1.3 is backwards compatible with all previous versions of DITA, so you should not have to adjust any DITA source files. But -- if the DITA source uses different DTDs -- as any content stored in the SDL product does, you'll need those DTDs, as they are different than the OASIS DTDs that ship with DITA-OT.
Hope this helps a little; you also might have better luck posting on the dita-users list at Yahoo!
Best,
Kris

Populating opcua address space with Nodes from an xml schema

Am working on a project to build an opc ua server from specification,
I've gone far enough on the implementation, am currently working on the write request, I already have a few nodes in the server address space.
There seem to be so many nodes, so many actually. It's almost impossible to create
and add the Nodes one by one.
Anyways back to the question, I've downloaded an xml file from opc foundation containing schema for all the nodes in the address space, Here is a link to the xml file
What is the most efficient way to create nodes from the xml file ? I am writing on a c95 compiler.
Below is a quick view of how Nodes are represented in the nodeset Xml file,
<Nodes>
<Node i:type="DataTypeNode">
<NodeId>
<Identifier>i=1</Identifier>
</NodeId>
<NodeClass>DataType_64</NodeClass>
<BrowseName>
<NamespaceIndex>0</NamespaceIndex>
<Name>Boolean</Name>
</BrowseName>
<DisplayName>
<Locale></Locale>
<Text>Boolean</Text>
</DisplayName>
<Description>
<Locale></Locale>
<Text>Describes a value that is either TRUE or FALSE.</Text>
</Description>
<WriteMask>0</WriteMask>
<UserWriteMask>0</UserWriteMask>
<RolePermissions />
<UserRolePermissions />
<AccessRestrictions>0</AccessRestrictions>
<References>
<ReferenceNode>
<ReferenceTypeId>
<Identifier>i=45</Identifier>
</ReferenceTypeId>
<IsInverse>true</IsInverse>
<TargetId>
<Identifier>i=24</Identifier>
</TargetId>
</ReferenceNode>
</References>
<IsAbstract>false</IsAbstract>
<DataTypeDefinition i:nil="true" />
</Node>
Programatically filling a running OPC-UA server with nodes is unacceptably slow.
you may want to investigate the ModelCompiler.
I found it fairly straightforward to fill a modeldesign XML with data and generate code and NodeSet2.xml. So even if you have no need for the generated C# code, which I suspect to be your case, this approach may be useful.
You may also want to look at the UA-.NETStandard repository.
It offers a method LoadFromXML method that reads your nodeset pretty quickly. You may find inspiration in this method.
Bon courage et un grand merci pour vos contributions au monde OPC-UA.
Maybe I'm a bit late, but I answer if it can help someone.
If you are using C/C++ with open62541 SDK I found that it is possible to generate *.c and *.h files to include in your opcua server, as described with some examples here: you only need to run a python program, providing some parameters and the name of output files to be generated, then include these files in your opcua server.
Another way that I found is using UaModeler by Unified Automation, in that case you can generate source files to include in your project, drawing your information model in the program and exporting it to xml or source files.

iPhone: repeating Elements in XML

I am new to XML parsing. I am parsing the following XML. There are tutorials for if XML has unique attributes but this XML has repeating attributes.
<?xml version="1.0" encoding="utf-8"?>
<start>
<Period periodType="A" fYear="2005" endCalYear="2005" endMonth="3">
<ConsEstimate type="High">
<ConsValue dateType="CURR">-8.9919</ConsValue>
</ConsEstimate>
<ConsEstimate type="Low">
<ConsValue dateType="CURR">-13.1581</ConsValue>
</ConsEstimate>
</Period>
< Period periodType="A" fYear="2006" endCalYear="2006" endMonth="3">
<ConsEstimate type="High">
<ConsValue dateType="CURR">-100.000</ConsValue>
</ConsEstimate>
<ConsEstimate type="Low">
<ConsValue dateType="CURR">-13.1581</ConsValue>
</ConsEstimate>
</Period>
</start>
I need to fetch the low and high values based on the years 2005 and 2006.
I agree with SB's comment, if you wan't to handle xml-datastructurse, you should know at least the basic stuff.
A good tutorial i can reccomend is ww3 schools XML Tutorial
once you did that, you should know that there are several ways to parse xml files. For flatfiles i recommend to use the TBXML Library, it is really fast and easy to handle within your code.

storing & reading xml files iPhone

I am using text-editor to store xml files.
I know how to read xml files in iPhone application. But the problem which do i get is explained below.
When I store xml files through text-editors, it looks perfect.
But when iPhone - xCode debugs, xml file data is shown as below.
What kind of mistake have I Done?
{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf460
{\fonttbl\f0\fmodern\fcharset0 Courier-Bold;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx480\tx960\tx1440\tx1920\tx2400\tx2880\tx3360\tx3840\tx4320\tx4800\tx5280\tx5760\tx6240\tx6720\tx7200\tx7680\tx8160\tx8640\tx9120\tx9600\tx10080\tx10560\tx11040\tx11520\tx12000\tx12480\tx12960\tx13440\tx13920\tx14400\tx14880\tx15360\tx15840\tx16320\tx16800\tx17280\tx17760\tx18240\tx18720\tx19200\tx19680\tx20160\tx20640\tx21120\tx21600\tx22080\tx22560\tx23040\tx23520\tx24000\tx24480\tx24960\tx25440\tx25920\tx26400\tx26880\tx27360\tx27840\tx28320\tx28800\tx29280\tx29760\tx30240\tx30720\tx31200\tx31680\tx32160\tx32640\tx33120\tx33600\tx34080\tx34560\tx35040\tx35520\tx36000\tx36480\tx36960\tx37440\tx37920\tx38400\tx38880\tx39360\tx39840\tx40320\tx40800\tx41280\tx41760\tx42240\tx42720\tx43200\tx43680\tx44160\tx44640\tx45120\tx45600\tx46080\tx46560\tx47040\tx47520\tx48000\ql\qnatural\pardirnatural
\f0\b\fs24 \cf0 \CocoaLigature0 \
Play Your ShotEvery golfer likes to hit the ball long, high and straight, but experience tells you that you can expect a certain pattern to your shots.Shots Curve From Sidehill LiesSidehill fairway lies will cause the ball to curve, slice right or hook left. Here's a tip to help make better contact.Don't Ground The DriverKeep the clubhead just off the ground to get your swing off to a consistently smooth start.Tilt Your TeeHere's a tip to "max out" into-the-wind drives.}
Above given data isn't my xml file.
I tried to save my xml file through textEditor.
But it prefix something before my xml data.
What should be done by me to avoid this problem?
my actual xml data is following.
<?xml version="1.0" encoding="ISO-8859-1"?>\
<tips><Prop_Tips><Tip_ID><![CDATA[1]]></Tip_ID><Tip_Title>Play Your Shot</Tip_Title><Tip_Description>Every golfer likes to hit the ball long, high and straight, but experience tells you that you can expect a certain pattern to your shots.</Tip_Description></Prop_Tips><Prop_Tips><Tip_ID><![CDATA[2]]></Tip_ID><Tip_Title>Shots Curve From Sidehill Lies</Tip_Title><Tip_Description>Sidehill fairway lies will cause the ball to curve, slice right or hook left. Here's a tip to help make better contact.</Tip_Description></Prop_Tips><Prop_Tips><Tip_ID><![CDATA[3]]></Tip_ID><Tip_Title>Don't Ground The Driver</Tip_Title><Tip_Description>Keep the clubhead just off the ground to get your swing off to a consistently smooth start.</Tip_Description></Prop_Tips><Prop_Tips><Tip_ID><![CDATA[4]]></Tip_ID><Tip_Title>Tilt Your Tee</Tip_Title><Tip_Description>Here's a tip to "max out" into-the-wind drives.</Tip_Description></Prop_Tips></tips>
Seems like you have written your XML file in a Rich Text Editor. It is saving the file in .rtf format, instead of raw text/xml.
Maybe the editor you are using has the option to save as raw txt. That should solve it.
You could also create the file using XCode. It will surely use raw txt.
Are you editing your XML file with TextEdit or something? You've got a whole bunch of RTF data in there, which would seem to imply that you're overwriting your XML data with RTF'd XML. Try using a text editor like Property List Editor or TextWrangler instead.