In case you're not terribly familiar with XML, let's spend
a few minutes talking syntax. Even if you are familiar,
it might make sense to follow along with this little
review. So in XML, elements are the basic building blocks
of an XML document. Now an XML element is composed
of an open tag and a closed tag, now this
is some data drawn from the New York Times developer
API Encourage you to have a look at this site.
We are going to look at some data from the most
popular API. These are for example articles that are most frequently
emailed among readers of the New York Times. Okay, so
let's look at a couple of examples here. So, the first
thing that we might notice about this particular document is
that we have some tags for num results or some elements
that have to do with the number of results. So,
this is actually result set from having done a query to
the most popular API and we've got a, an
element that tells us how many results were identified
by our query. And then the list of results
follows. Now this happens to be a single result here.
And we can see that this result begins right
here with this open tag and closes right here
with this close tag. Okay. Now just as a
couple of other examples of the data within this particular
result, we can take a look at the byline, note that
it's got a close tag, as well. And some of the
other elements, here if you note the title for example, this
happens to be an article about bedbugs. Okay. So, this provides an
example using some really nicely named tags. We know what these
mean. Now, there's another aspect of XML that we need to concern
ourselves with especially given some of the exercises that we're going
to have. Later on. And those have to do with attributes for
XML elements. Now, this document provides a number of very
nice examples of elements in XML. But what we don't
have here are any examples of attributes for any of
these elements being used. So what I'd like to do here
is talk about essentially the two types of data that
we're going to look at that have been encoded in XML. One
is this more documented oriented type of XML, which is
originally the type of data that XML was designed to encode.
But then we can also take a look at
something like this. Okay, now this is actual data from
the open street map project. This is a pretty close
zoomed in view from Open street map of West Belmont
avenue. Particularly the 1000 block. And you can see right
here, there's a Giardano's Restaurant here. Giardano's is a famous
pizza chain in Chicago. So, this is data that is
essentially from a layer on top of that particular map.
This is data that is human created. So, users
of Open Street Map have actually added this data on
top of the map data. And what I want to point out here is that this is very much
not document oriented. This is just data. Okay? And
a lot of times you see HTML used in this
way, you'll see that attributes are heavily used. So
in this particular example, this is the node that represents
the Giordano's restaurant. We can see that there is
a number of attributes specified for this particular element.
Common among them are the latitude and longitude attributes
that this particular annotation applies to. So, essentially what
this data element provides is a mapping from geographic
coordinates to more common street address coordinates. Okay? So
this is a good example of attributes in XML
and there's one other thing that I want to point
out here. And that is this type of tag here.
Now in this particular data they're doing something that I probably
wouldn't do, but it is the type of thing that
you're going to see as a data scientist and likely already
have. Essentially, they've just got a bunch of key value
pairs that are encoded in something called a tag element. And,
in this case, none of these tag elements have a
close tag. Instead, they use this special xml syntax where you
can simply create what are called empty tags, that
is tags that don't have any content. All of
the data for this type of tag is contained
directly within its attributes. So the most emailed example
here provides us a nice example of document oriented
XML with lots of content inside the elements. And
this particular example from your [INAUDIBLE] project provides us
with other end of this spectrum which is very
data oriented XML where all or almost all of the data
is contained within attributes for the individual elements and in this
types of cases, you often have mostly or at least many
empty elements within the XML data that you are looking at.
إذا لم تكن على دراية بتنسيق XML، فلنتحدث قليلاً عن
،صيغته. حتى لو كنت على دراية به
فقد يكون منطقيًا إجراء القليل من
المراجعة. فباستخدام تنسيق XML، تصبح العناصر هي اللبنات الأساسية
لمستند XML. يتألف الآن عنصر XML
،من علامة مفتوحة وعلامة مغلقة
وهذه بعض البيانات المشتقة من واجهة برمجة تطبيقات مطور جريدة
.New York Times والتي تدفعكم إلى إلقاء نظرة على هذا الموقع
سنلقي نظرة على بعض البيانات المشتقة من أشهر
واجهة برمجة تطبيقات. على سبيل المثال، هذه المقالات هي الأكثر تداولاً
،عبر البريد الإلكتروني بين قراء جريدة New York Times. حسنًا
لنلقِ نظرة على مثالين هنا. أول شيء
يمكننا ملاحظته فيما يتعلق بهذا المستند تحديدًا
هو وجود بعض العلامات لنتائج الأرقام أو بعض العناصر
،التي يجب اقترانها بعدد النتائج. إذًا
فإن مجموعة النتائج هذه هي التي يتم من خلالها إجراء استعلام
لأشهر واجهة برمجة تطبيقات، ويوجد لدينا
عنصر يخبرنا بعدد النتائج التي تم تحديدها
من خلال الاستعلام الذي أجريناه. ثم تتبعه قائمة
.بالنتائج. وتظهر هذه كنتيجة واحدة هنا
ويمكننا ملاحظة أن هذه النتيجة تبدأ هنا
بعلامة الفتح هذه وتنغلق هنا
بعلامة الإغلاق هذه. Okay. الآن وعلى غرار
مثالين آخرين من البيانات ضمن هذه النتيجة
بعينها، يمكننا إلقاء نظرة على byline وملاحظة
اشتمالها على علامة إغلاق أيضًا. وكذلك بعض العناصر
الأخرى هنا، وذلك إذا لاحظت العنوان على سبيل المثال، فقد تمثل
مقالة عن بق الفراش. Okay. إذًا، فإن هذا يعرض
مثالاً لاستخدام بعض العلامات المسماة تسمية حسنة الصياغة. حيث نعلم
ما تعنيه هذه العلامات. كما يوجد جانب آخر لتنسيق XML يلزمنا الانتباه
له، خاصةً بالنظر إلى بعض التمارين التي سنتطرق
إليها. بعد قليل. وستتناول هذه التمارين سمات
عناصر XML. يعرض هذا المستند عددًا من
الأمثلة الجيدة للغاية لعناصر بتنسيق XML. ولكن لا يتوفر لدينا
هنا أي أمثلة للسمات الخاصة بأي من
هذه العناصر قيد الاستخدام. وأود هنا
التحدث بشكل أساسي عن نوعين من البيانات
سنلقي نظرة عليهما حيث تم ترميزهما بتنسيق XML. يتمثل أحدهما
في نوع تنسيق XML الموجّه بشكل أكبر إلى المستندات، وهو
.في الأصل نوع من البيانات الذي تم تصميم تنسيق XML لترميزه
يمكننا بعد ذلك إلقاء نظرة على
شيء كهذا. حسنًا، تظهر الآن هذه البيانات الفعلية المشتقة من
مشروع خريطة الشارع المفتوحة. هذه صورة مكبرة عن قرب
بطريقة عرض واردة من خريطة شارع مفتوحة خاصة بطريق
مدينة بلمونت الغربية. وتحديدًا الحاجز رقم 1000. ويمكنك ملاحظة وجود
مطعم جياردانو هنا. وهي سلسلة مطاعم بيتزا
شهيرة في مدينة شيكاغو. إذًا، هذه هي البيانات
.الواردة في الأساس من إحدى الطبقات الموجودة أعلى تلك الخريطة تحديدًا
هذه هي البيانات التي تم إنشاؤها بواسطة عنصر بشري. إذًا، فإن مستخدمي
خريطة الشارع المفتوحة قد أضافوا فعليًا هذه البيانات
أعلى بيانات الخريطة. وأريد الإشارة هنا إلى أن هذه البيانات
ليست موجهة بقدر كبير للغاية إلى المستندات. فهذه ليست سوى بيانات. Okay? وتلاحظ
استخدام تنسيق HTML مرات كثيرة بهذه
الطريقة، كما ستلاحظ استخدام السمات بشكل مكثف. ففي
هذا المثال تحديدًا، هذه هي العقدة التي تمثل
مطعم جياردانو. ويمكننا ملاحظة وجود
.عدد من السمات المحددة لهذا العنصر بعينه
وأبرز هذه السمات هي خط الطول وخط العرض
اللذان ينطبق عليهما هذا التعليق التوضيحي تحديدًا. لذا فإن عنصر البيانات
هذا يعرض في الأساس تخطيطًا مشتقًا من إحداثيات
،جغرافية لإحداثيات عنوان شارع أكثر شيوعًا. Okay? إذًا
،هذا مثال جيد لسمات بتنسيق XML
وأريد الإشارة إلى شيء
.آخر هنا. وهو يتمثل في هذا النوع من العلامات هنا
فهذه البيانات تحديدًا ستنفّذ شيئًا من المرجح
أنني لم أنفّذه، ولكنه نوع من الأشياء التي
ستلاحظها بصفتك عالم بيانات ومن المرجح أن تكون
صادفتها. في الأساس، توجد مجموعة من أزواج قيم المفاتيح
التي تم ترميزها بشيء يطلق عليه عنصر علامة. وفي
هذه الحالة الماثلة، لا يشتمل أي من عناصر العلامة هذه على
علامة إغلاق. أو تستخدم صيغة xml الخاصة هذه حيث
يمكنك ببساطة إنشاء ما يطلق عليه بالعلامات الفارغة
التي لا تتضمن أي محتوى. ويتم تضمين جميع
بيانات هذا النوع من العلامات
مباشرةً داخل سماته. حيث يعرض لنا أكثر الأمثلة تداولاً عبر البريد الإلكتروني
هنا تنسيق XML موجهًا
لمستند مع كم كبير من المحتويات داخل العناصر. ويمدنا
هذا المثال المشتق بعينه من [INAUDIBLE] المشروع
بجانب آخر من هذا النطاق الذي يُعد تنسيق XML
موجهًا توجيهًا بالغًا للبيانات حيث يتم تضمين جميع البيانات أو معظمها
،داخل سمات العناصر الفردية
وعادةً ما يوجد لديك في هذه الحالات العديد من العناصر الفارغة
.ضمن بيانات XML التي تتفحصها
In case you're not terribly familiar with XML, let's spend
a few minutes talking syntax. Even if you are familiar,
it might make sense to follow along with this little
review. So in XML, elements are the basic building blocks
of an XML document. Now an XML element is composed
of an open tag and a closed tag, now this
is some data drawn from the New York Times developer
API Encourage you to have a look at this site.
We are going to look at some data from the most
popular API. These are for example articles that are most frequently
emailed among readers of the New York Times. Okay, so
let's look at a couple of examples here. So, the first
thing that we might notice about this particular document is
that we have some tags for num results or some elements
that have to do with the number of results. So,
this is actually result set from having done a query to
the most popular API and we've got a, an
element that tells us how many results were identified
by our query. And then the list of results
follows. Now this happens to be a single result here.
And we can see that this result begins right
here with this open tag and closes right here
with this close tag. Okay. Now just as a
couple of other examples of the data within this particular
result, we can take a look at the byline, note that
it's got a close tag, as well. And some of the
other elements, here if you note the title for example, this
happens to be an article about bedbugs. Okay. So, this provides an
example using some really nicely named tags. We know what these
mean. Now, there's another aspect of XML that we need to concern
ourselves with especially given some of the exercises that we're going
to have. Later on. And those have to do with attributes for
XML elements. Now, this document provides a number of very
nice examples of elements in XML. But what we don't
have here are any examples of attributes for any of
these elements being used. So what I'd like to do here
is talk about essentially the two types of data that
we're going to look at that have been encoded in XML. One
is this more documented oriented type of XML, which is
originally the type of data that XML was designed to encode.
But then we can also take a look at
something like this. Okay, now this is actual data from
the OpenStreetMap project. This is a pretty close
zoomed in view from OpenStreetMap of West Belmont
avenue. Particularly the 1000 block. And you can see right
here, there's a Giardano's Restaurant here. Giardano's is a famous
pizza chain in Chicago. So, this is data that is
essentially from a layer on top of that particular map.
This is data that is human created. So, users
of OpenStreetMap have actually added this data on
top of the map data. And what I want to point out here is that this is very much
not document oriented. This is just data. Okay? And
a lot of times you see HTML used in this
way, you'll see that attributes are heavily used. So
in this particular example, this is the node that represents
the Giordano's restaurant. We can see that there is
a number of attributes specified for this particular element.
Common among them are the latitude and longitude attributes
that this particular annotation applies to. So, essentially what
this data element provides is a mapping from geographic
coordinates to more common street address coordinates. Okay? So
this is a good example of attributes in XML
and there's one other thing that I want to point
out here. And that is this type of tag here.
Now in this particular data they're doing something that I probably
wouldn't do, but it is the type of thing that
you're going to see as a data scientist and likely already
have. Essentially, they've just got a bunch of key value
pairs that are encoded in something called a tag element. And,
in this case, none of these tag elements have a
close tag. Instead, they use this special xml syntax where you
can simply create what are called empty tags, that
is tags that don't have any content. All of
the data for this type of tag is contained
directly within its attributes. So the most emailed example
here provides us a nice example of document oriented
XML with lots of content inside the elements. And
this particular example from your OpenStreetMap project provides us
with other end of this spectrum which is very
data oriented XML where all or almost all of the data
is contained within attributes for the individual elements and in this
types of cases, you often have mostly or at least many
empty elements within the XML data that you are looking at.
Caso você não esteja muito familiarizado com o XML, vamos gastar
alguns minutos falando sobre sintaxe. Mesmo que esteja familiarizado,
pode fazer sentido acompanhar esta pequena
revisão. No XML, os elementos são os blocos de construção básicos
de um documento XML. Um elemento XML é composto
de uma tag de abertura e uma tag de fechamento. Agora, isso
são alguns dados extraídos de API
do New York Times Developer. Recomendo que você dê uma olhada neste site.
Vamos analisar alguns dados de The most
popular API. Estes são exemplos de artigos mais frequentemente
enviados por email por leitores do New York Times. Certo.
Vejamos alguns exemplos aqui. A primeira
coisa que talvez percebamos sobre este documento em particular é
que ele tem algumas tags num_results ou alguns elementos
relacionados ao número de resultados. Então,
isso é, na verdade, o conjunto de resultados de uma consulta realizada sobre
The most popular API. E obtemos um
elemento que os indica quantos resultados foram
identificados pela consulta. E, em seguida, a lista de resultados
continua. Acontece que este é um resultado único.
E podemos ver que este resultado começa aqui,
com esta tag de abertura, e termina aqui,
com esta tag de fechamento. Certo. Agora, assim como
com vários outros exemplos de dados neste resultado
específico, podemos verificar o byline. Observe que
ele também tem uma tag de fechamento. E alguns outros
elementos. Aqui, se você observar a tag title, por exemplo,
parece que este é um artigo sobre percevejos. Certo. Portanto, isso fornece
um exemplo de uso de algumas tags perfeitamente nomeadas. Sabemos o que elas
significam. Agora, há um outro aspecto do XML com o qual precisamos
nos preocupar, especialmente em alguns dos exercícios que vamos
realizar posteriormente. E eles têm a ver com atributos para
elementos XML. Agora, este documento fornece vários exemplos
muito bons de elementos XML. Mas o que não
temos aqui são exemplos de atributos para
esses elementos que estão sendo usados. Então, o que eu gostaria de fazer aqui
é falar, essencialmente, sobre os dois tipos de dados que
iremos analisar e que foram codificados em XML. Um
é esse tipo de XML mais voltado para documentos que,
originalmente, é o tipo de dados que o XML foi projetado para codificar.
Mas também podemos analisar
algo deste tipo. Muito bem. Agora, estes são dados reais do
projeto Open Street Map. Esta é uma visualização
muito aproximada da West Belmont Avenue
pelo Open Street Map. Especificamente, do quarteirão nº 1.000. E você pode ver que aqui,
há um restaurante Giardano. Giardano é uma famosa
rede de pizzarias em Chicago. Bem, estes são dados
essencialmente de uma camada superior daquele determinado mapa.
Estes são dados criados por pessoas. Portanto, os usuários
do Open Street Map adicionaram esses dados
por cima dos dados do mapa. E o que eu quero destacar aqui é que isso é não é
muito voltado a documentos. Isso são apenas dados. Certo? Muitas
vezes, quando vir o XML ser usado desta
maneira, você verá que os atributos são muito utilizados. Neste
exemplo específico, este é o nó que representa
o restaurante Giordano. Podemos ver que existem
vários atributos especificados para este elemento em particular.
Comum entre eles estão os atributos latitude e longitude que se
aplicam a esta anotação em particular. Essencialmente, o que estes
elementos de dados fornecem é um mapeamento de coordenadas
geográficas para coordenadas de endereços mais comuns. Certo? Portanto,
este é um bom exemplo de atributos no XML.
E tem mais uma coisa que quero destacar
aqui. E é este tipo de tag aqui.
Agora, nestes dados em particular, foi feito algo que eu provavelmente
não faria, mas é o tipo de coisa que
você, como um cientista de dados, verá ou, provavelmente, já
viu. Essencialmente, foram usados vários pares chave-valor
codificados em algo chamado de elemento tag. E,
neste caso, nenhum desses elementos tag tem uma
tag de fechamento. Em vez disso, é usada esta sintaxe especial do XML, em que
é possível apenas criar as chamadas tags vazias, que
são tags que não têm nenhum conteúdo. Todos os
dados deste tipo de tag estão contidos
diretamente em seus atributos. Então, o exemplo de email mais enviado
aqui nos fornece um bom exemplo de XML
voltado a documentos com vários conteúdos dentro dos elementos. E
este exemplo em particular do projeto Open Street Map nos fornece
a outra ponta desse espectro, que é o XML bastante
voltado a dados, no qual todos ou quase todos os dados
estão dentro de atributos de elementos individuais e, nesses
tipos de casos, você geralmente encontra a maioria ou, pelo menos, muitos
elementos vazios nos dados XML que está analisando.
如果你对 XML 还没有熟悉到如数家珍 我们就花点时间
谈一谈语法 即使你对它已经比较熟悉
再稍微复习复习也会很有意义
在 XML 中 元素就是构成 XML 文档的基本积木块
一个 XML 元素含有
一个开始标记和一个结束标记
这是从《纽约时报》API 开发者处摘录的一些数据
鼓励大家看看这个网站
我们要来看一些从最受欢迎的 API 处获得的数据
比如 这些是《纽约时报》读者 用电子邮件
发送最多的文章
我们来看几个例子 对于这个文档
我们可能首先会注意到的是
有一些 num 结果的标记 或者
与结果数相关的一些元素
这个实际是一个结果集 它来自一次
针对最受欢迎的 API 的查询 并且我们得到了一个元素
该元素告诉我们 通过我们的查询 识别出了多少结果
接下来是结果列表
这里凑巧是一个单一的结果
我们可以看到该结果从这里开始
从这个开始标记开始 然后到这个
结束标记结束 好 再来看看
这条结论中数据的另外几个例子
我们可以看看署名栏 注意
它也带有一个结束标记 还有一些
其它元素 如果你注意这个标题的话会发现
它正好是一篇有关臭虫的文章 那么 这个例子
所用的名字非常棒 我们知道这些代表什么
现在 我们要了解 XML 的一个需要特别关注的方面
因为我们将要做的一些练习会用到
这个稍后说 这些与 XML 元素的属性有关
看这里 这个文档提供给了很多
XML 中元素的很好的例子 不过这里缺乏的是
与所用的这些元素的属性相关的例子
所以我要做的就是
主要谈一谈我们将要看到的两种类型的数据
它们是在 XML 中编码的
一个是较为面向文档的 XML 类型
这种类型最初是 XML 用来编码的数据类型
不过现在我们仍然可以看看
类似的数据 看 这是来自 OpenStreetMap 项目的实际数据
这是 OpenStreetMap 中西贝尔蒙特大道
的较近距离视角图
尤其是1000号街区 大家可以在这里看到
有一家 Giardano's 餐厅 Giardano's 是芝加哥的一家
著名的匹萨连锁餐厅 该数据主要来自于
该地图基础上的一个图层
该数据是人为创造的
事实上是 OpenStreetMap 的用户在地图数据的基础上添加了这个数据
这里我想要指出的是 这个数据
非常的“不面向文档” 它只是数据 知道吗?
大家很多时候都会看到 HTML 以这种方式使用
你会看到属性被大量应用
那么在这个例子中 这个节点代表的是
Giordano's 餐厅 我们可以看到
这里有很多针对这个元素的属性
它们都具有经度和纬度属性
这些属性都适用于这条注释 因此 基本上
这个数据元素提供的是地理坐标
到更为常用的街道地址坐标的映射 对吧?
因此 这是个 XML 中属性的很好的例子
我还想要指出一点
就是标签的类型
在该数据中 它们会做一些
我可能不会做的事情 不过作为数据科学家
你将来会看到这类东西 或许你们已经看到了
基本上 它们已经具备有一系列关键值对
这些关键值对被编码在所谓的标签元素中
在该情况下 这些标签元素都不具备
结束标签 相反 它们采用这种特殊的 xml 语法
你可以仅创建出所谓的空标签
即没有内容的标签
这种类型的标签的所有数据
是直接包含在其属性中的 这个电子邮件中使用最多的例子
是一个很好的面向文档的
元素中含很多内容的 XML 的例子
这个 OpenStreetMap 项目中的例子告诉我们
光谱的另一端是非常面向数据的 XML
其中所有或几乎所有数据
都包含在单个元素的属性中
在这种情况下 你看到的 XML 数据中 大多数会是空元素
或者至少很多都是空元素