我想提取<Page>
节点内的所有节点。 我使用下面的方法通过使用以下两种方法如何查找XML中特定标记内的所有标记
doc.getElementsByTagName("*"); //getting all the nodes
doc.getElementsByTagName("name"); //getting nodes <name>
找到一个XML文档中的所有节点,但我想找到一个特定的节点内的所有节点。例如我想要<page>
内的所有节点。请给我建议的方式来做到这一点...
<Pages>
<Page>
<Diagram>
<Widgets>
<Image>
<Name>YmcLogo</Name>
<Rectangle>
<Rectangle X="0" Y="4" Width="130" Height="28" />
</Rectangle>
<Bold>False</Bold>
<BorderColor>Color(argb) = (255, 0, 0, 0)</BorderColor>
<BorderWidth>-1</BorderWidth>
<FillColor>Color(argb) = (255, 255, 255, 255)</FillColor>
<FontName>Arial</FontName>
<FontSize>9.75</FontSize>
<ForeColor>Color(argb) = (255, 0, 0, 0)</ForeColor>
<HorizontalAlignment>Center</HorizontalAlignment>
<Italic>False</Italic>
<Underline>False</Underline>
<VerticalAlignment>Center</VerticalAlignment>
<Widgets>
<TextPanel>
<Html><p style="font-size:13px;text-align:center;line-height:normal;"><span style="font-family:'Arial Regular', 'Arial';font-weight:400;font-style:normal;font-size:13px;color:#000000;text-align:center;line-height:normal;">&nbsp;</span></p></Html>
<Name />
<Rectangle>
<Rectangle X="2" Y="6" Width="126" Height="16" />
</Rectangle>
<Bold>False</Bold>
<BorderColor>Color(argb) = (255, 0, 0, 0)</BorderColor>
<BorderWidth>-1</BorderWidth>
<FillColor>Color(argb) = (255, 255, 255, 255)</FillColor>
<FontName>Arial</FontName>
<FontSize>9.75</FontSize>
<ForeColor>Color(argb) = (255, 0, 0, 0)</ForeColor>
<HorizontalAlignment>Center</HorizontalAlignment>
<Italic>False</Italic>
<Underline>False</Underline>
<VerticalAlignment>Center</VerticalAlignment>
</TextPanel>
</Widgets>
</Image>
<ShapeType>H2</ShapeType>
<Annotation>
<Properties>
<PropertyValue PropertyName="ContainerType">conditionContainer</PropertyValue>
</Properties>
</Annotation>
<FootnoteNumber>1</FootnoteNumber>
<Name>SCMProductGroup</Name>
<Rectangle>
<Rectangle X="72" Y="110" Width="127" Height="15" />
</Rectangle>
<Underline>False</Underline>
<VerticalAlignment>Near</VerticalAlignment>
</Shape>
<Textbox>
<Text />
<Annotation>
<Properties>
<PropertyValue PropertyName="ContainerType">conditionContainer</PropertyValue>
<PropertyValue PropertyName="field_label[多言語対応用キー][多语言对应Key]">label.scmProductGroup</PropertyValue>
<PropertyValue PropertyName="type">text</PropertyValue>
<PropertyValue PropertyName="cvcodeobjary ">scmProductGrp</PropertyValue>
<PropertyValue PropertyName="cvcontainerobjary ">scmProductGrpNm</PropertyValue>
<PropertyValue PropertyName="cvfieldstrary ">scmProductGrpName</PropertyValue>
<PropertyValue PropertyName="cvopenmethod ">scmProductGrp_ajax_codeValue</PropertyValue>
<PropertyValue PropertyName="maxlength[桁数-最大][最大位数]">3</PropertyValue>
<PropertyValue PropertyName="size">3</PropertyValue>
</Properties>
</Annotation>
</Textbox>
<Textbox>
<Text />
<Annotation>
<Properties>
<PropertyValue PropertyName="ContainerType">conditionContainer</PropertyValue>
<PropertyValue PropertyName="type">text</PropertyValue>
<PropertyValue PropertyName="datatype">String</PropertyValue>
<PropertyValue PropertyName="styleClass">display</PropertyValue>
<PropertyValue PropertyName="full-width">False</PropertyValue>
<PropertyValue PropertyName="half-width-al">True</PropertyValue>
<PropertyValue PropertyName="half-width-num">False</PropertyValue>
<PropertyValue PropertyName="half-width-other">False</PropertyValue>
</Properties>
</Annotation>
</Textbox>
<Table>
<Annotation>
<Properties>
<PropertyValue PropertyName="ContainerType">DhtmlX Grid Container</PropertyValue>
<PropertyValue PropertyName="maxlength[桁数-最大][最大位数]">3</PropertyValue>
<PropertyValue PropertyName="size">3</PropertyValue>
<PropertyValue PropertyName="group-name">1</PropertyValue>
<PropertyValue PropertyName="group-type">list</PropertyValue>
<PropertyValue PropertyName="collection">result</PropertyValue>
<PropertyValue PropertyName="edit[入出力区分][输入区分]">true</PropertyValue>
<PropertyValue PropertyName="sort">True</PropertyValue>
</Properties>
</Annotation>
<FootnoteNumber>5</FootnoteNumber>
<Name>DHTMLXgrid</Name>
<Rectangle>
<Rectangle X="20" Y="180" Width="812" Height="140" />
</Rectangle>
</Table>
</Widgets>
</Diagram>
<PackageInfo>
<Name>01::inquiry::list</Name>
</PackageInfo>
</Page>
</Pages>
这是好的milez我能够提取所有的页面节点,但我想要一个页面节点内的所有节点。 – SOP
这是childList的功能吗?每个'node'都是一个页面,你可以调用getChildNodes来得到另一个层次的节点 – milez
childNode只返回节点下的一个层次。它永远不会返回任何节点内的所有节点。 – SOP