将 XML 写回 iPhone 上的网络服务器
我正在编写一个 iPhone 应用程序,用于查找当地酒吧/社交场所的线路信息。在应用程序中,我从 Web 服务器解析 XML 文件。以下是 XML 的结构:
<?xml version="1.0" encoding="UTF-8"?>
<Bars>
<Bar>Kam's</Bar>
<Line>10</Line>
<Bar>Cly's</Bar>
<Line>10</Line>
<Bar>Joe's</Bar>
<Line>10</Line>
<Bar>The Red Lion</Bar>
</Bars>
然后,该数据显示在表格视图中,并显示条形图和线条图。如果用户选择表中的某个元素,则会出现 uiactionview 并请求用户更新该特定栏的行信息。我知道如何接受用户的输入。
我遇到的问题(我真的不知道从哪里开始)是弄清楚如何重写 XML 并将其放回 Web 服务器上的同一位置。有谁知道教程或者可以让我开始使用这个吗?
非常感谢。
I am writing an iPhone application that will be used to find the line information at local bars/social spots. In the application, I parse an XML file from a web server. Here is the structure of the XML:
<?xml version="1.0" encoding="UTF-8"?>
<Bars>
<Bar>Kam's</Bar>
<Line>10</Line>
<Bar>Cly's</Bar>
<Line>10</Line>
<Bar>Joe's</Bar>
<Line>10</Line>
<Bar>The Red Lion</Bar>
</Bars>
This data is then displayed in a tableview with the Bar and the Line shown. If a user selects an element in the table, a uiactionview appears and requests for the user to update the line information for that particular bar. I know how to take the users input.
The problem I am having, and I really don't know where to begin, is figuring out how to rewrite the XML and put it back in the same location on the web server. Does anyone know of a tutorial or could possibly get me started with this?
Thanks so much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,我将回答您的直接问题,但我必须指出,您发布的内容不是正确的 XML。行号应该是属性,或者是 Bar 节点的子节点。以下任一情况都被认为是正确的:
或者
还有更多的方法来表示它,但 XML 规范不遵循节点排序。解析器通常会将它们从头到尾排序,但不能保证,因此您的
Line
节点可能会与错误的Bar
关联。不管怎样,也就是说,您需要一些不同的工具,而且它们的细节太多,无法在此处的答案中写出,因此我将向您指出文档。
1) 要与服务器通信(获取 XML 或检索它),您可能需要使用 NSURLConnection。 这里Apple 的教程。
2) 对于解析 XML,Apple 仅提供 SAX 解析器。对于您来说,这将是一个陡峭的学习曲线,而且它也无法编写您需要编写的 XML。我将引导您访问另一篇 StackOverflow 帖子,因为它是更详细地了解如何寻找优秀的第 3 方 XML 解析器。
3) 如果您不知道如何设置可以提供 XML 文档并接受 POSTed XML 内容的服务器,那就是一大堆蠕虫了。我建议您从一个简单的“LAMP”堆栈开始,然后阅读 PHP。
干杯!
So I'll answer your direct question, but I have to mention that what you've posted is not proper XML. The line numbers should be attributes, or sub-nodes of the Bar nodes. Either of the following would be considered correct:
or
There are even more ways to represent it, but the XML spec does not honor node ordering. A parser will generally order them first to last, but there's no guarantee, so your
Line
nodes may get associated with the wrongBar
.Anyway, that said, you need a few different tools, and they are far too many details to write out in an answer here so I'll point you to the documentation.
1) To communicate with the server (either get the XML, or retrieve it) you'll probably want to use NSURLConnection. Here's Apple's tutorial on it.
2) For parsing the XML, Apple only supplies a SAX parser. It's going to be a steep learning curve for you, and it also cannot write XML, which you need to do. I'm going to direct you to this other StackOverflow post, since it goes into more detail about finding a good 3rd party XML parser.
3) If you don't know how to set up a server that can serve an XML document, and accept POSTed XML content, that's a whoooole other bag of worms. I would suggest you start with a simple "LAMP" stack, and read up on PHP.
Cheers!