寻求建议:DOMDocument identifiyingparent-childrelationships between Nodes
我有一个包含 2 个父节点的 XML 文件,在第二个父节点中,还有另一个父节点和子节点。
<product>
<upc>677446126665</upc>
<modelNumber>Content</modelNumber>
<categoryPath>
<category>
<name>Content</name>
</category>
<category>
<name>Content</name>
</category>
<category>
<name>Content</name>
</category>
<category>
<name>Content</name>
</category>
</categoryPath>
</product>
我不是在找人给我代码,我只是想了解它是如何工作的。
是
<categoryPath> </categoryPath>
子节点,还是父节点?他们是使用 PHP 原生 DOMDocument 库的简单方法吗?它可以让我完全删除categoryPath以及每个名称节点的父节点(类别)
最终我会得到一个像这样的文档:
<product>
<upc>44444</upc>
<modelNumber>d</modelNumber>
<name></name>
<name></name>
<name></name>
<name></name>
</product>
再次,我询问之间的父子关系这些节点,我并不是要求某人给我解决这个问题的代码。
I have an XML file that contains 2 parents nodes, and within the second parent node, there is another parent and child node.
<product>
<upc>677446126665</upc>
<modelNumber>Content</modelNumber>
<categoryPath>
<category>
<name>Content</name>
</category>
<category>
<name>Content</name>
</category>
<category>
<name>Content</name>
</category>
<category>
<name>Content</name>
</category>
</categoryPath>
</product>
I'm not looking for someone to to give me the code, I just want to understand how this works.
Is
<categoryPath> </categoryPath>
a child node, or a parent node? Is their a trivial approach using PHP native DOMDocument library that can allow me to remove categoryPath completely along with each of the name node's parent node (category)
Ultimately I would have a document like this:
<product>
<upc>44444</upc>
<modelNumber>d</modelNumber>
<name></name>
<name></name>
<name></name>
<name></name>
</product>
Again, I am asking about the parent child relationship between these nodes, I'm not asking for someone to just give me the code to solve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
父关系
product
是upc
、modelNumber
和categoryPath
的父。categoryPath
是category
的父级。category
是name
的父级。子关系
name
是category
的子。category
是categoryPath
的子。categoryPath
是product
的子。所以
既是父节点又是子节点。您可以:
DOMNode::cloneNode)
DOMNode::removeChild)
DOMNode::appendChild)
以下 XML 教程说明了 XML 元素之间的关系。
Parent Relationship
product
is the parent ofupc
,modelNumber
, andcategoryPath
.categoryPath
is the parent ofcategory
.category
is the parent ofname
.Child Relationship
name
is the child ofcategory
.category
is a child ofcategoryPath
.categoryPath
is a child ofproduct
.So
<categoryPath>
is both a parent node and a child node.You could:
DOMNode::cloneNode)
DOMNode::removeChild)
DOMNode::appendChild)
The following XML tutorial illustrates the relationships between XML elements.