获取oracle 获取xmltpye节点中的属性值

获取oracle 获取xmltpye节点中的属性值,第1张

实现思路:可以通过w3c的dom解析器进行 *** 作,之后通过getName获取到xmltpye中的属性值。

举例:

import javaioFile;

import javaxxmlparsersDocumentBuilder;

import javaxxmlparsersDocumentBuilderFactory;

import orgw3cdomDocument;

import orgw3cdomElement;

import orgw3cdomNodeList;

public class DomTest1

{

public static void main(String[] args) throws Exception

{

// step 1: 获得dom解析器工厂(工作的作用是用于创建具体的解析器)

DocumentBuilderFactory dbf = DocumentBuilderFactorynewInstance();

// Systemoutprintln("class name: " + dbfgetClass()getName());

// step 2:获得具体的dom解析器

DocumentBuilder db = dbfnewDocumentBuilder();

// Systemoutprintln("class name: " + dbgetClass()getName());

// step3: 解析一个xml文档,获得Document对象(根结点)

Document document = dbparse(new File("candidatexml"));

NodeList list = documentgetElementsByTagName("PERSON");

for(int i = 0; i < listgetLength(); i++)

{

Element element = (Element)listitem(i);

String content = elementgetElementsByTagName("NAME")item(0)getFirstChild()getNodeValue();

Systemoutprintln("name:" + content);

Systemoutprintln("--------------------------------------");

}

}

}

Private Sub Command1_Click()

Dim Dom As New DOMDocument

Domasync = False

DomLoad "axml"

Dim node As IXMLDOMNode

Set node = DomselectSingleNode("root")selectSingleNode("order")Dim x As IXMLDOMNode

For Each x In nodechildNodes

MsgBox xAttributesgetNamedItem("订单编号")Text

MsgBox xAttributesgetNamedItem("下单时间")Text

Next

Set Dom = Nothing

End Sub

xml="<note><to>George</to><from>John</from><heading>Reminder</heading ><body remark=""szqlay"">Don't forget the meeting!</body></note>"

Dim xmldocSet xmldoc = WScriptCreateObject("msxml2domdocument")

xmldocasync=false

xmldocloadxml(xml)

dim cnode

Set cnode=xmldocgetElementsByTagName("body")item(0)

MsgBox cnodetext 

MsgBox cnodeattributesitem(0)text

说实在,用数字作标签估计行不通,我试了下不能。这是用vbs脚本,或许放到vb中也行。你可自己把body改成数字试一下。

import javaxxmlparsersDocumentBuilder;

import javaxxmlparsersDocumentBuilderFactory;

import orgw3cdomDocument;

import orgw3cdomNode;

import orgw3cdomNodeList;

public class DomTest_02 {

/

@param args

/

public static void main(String[] args) throws Exception{

// TODO Auto-generated method stub

DocumentBuilderFactory dbf = DocumentBuilderFactorynewInstance();

DocumentBuilder db = dbfnewDocumentBuilder();

Document doc = dbparse("d:/nodexml");

// Element root = docgetDocumentElement();

Node root = docgetFirstChild();

if(rootgetNodeType() == NodeELEMENT_NODE){

String str1 = rootgetAttributes()getNamedItem("name")getNodeValue();

String str2 = rootgetAttributes()getNamedItem("alias")getNodeValue();

String str3 = rootgetAttributes()getNamedItem("group")getNodeValue();

Systemoutprintln("name="+str1+" alias="+str2+" group="+str3);

}

NodeList nodelist = rootgetChildNodes();

for(int j=0;j<nodelistgetLength();j++){

Node node = nodelistitem(j);

if(nodegetNodeType() == NodeELEMENT_NODE){

String s1 = nodegetAttributes()getNamedItem("number")getNodeValue();

String s2 = nodegetAttributes()getNamedItem("alias")getNodeValue();

Systemoutprintln("number="+s1+" alias="+s2);

}

}

}

}

以上就是关于获取oracle 获取xmltpye节点中的属性值全部的内容,包括:获取oracle 获取xmltpye节点中的属性值、VB读取XML节点属性值、高分悬赏 VB 根据节点名字获取XML文件中的对应节点的属性值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9804461.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-02
下一篇2023-05-02

发表评论

登录后才能评论

评论列表(0条)

    保存