2013年9月16日星期一

java xml file processing problems encountered

Xml file in the java process when it came to the following question:
powerdesigner design table has a primary key in the case . PDM generated xml file will be generated in the following lines of code :

<c:PrimaryKey>
  <o:Key Ref="o30" />
</c:PrimaryKey>



Then I deal with java , you can read the primary key information , as follows:


String keyId = ((Element) tableNode.selectSingleNode("c:PrimaryKey/o:Key")).attributeValue("Ref");


but some I did not design the table primary key , so it does not produce c: PrimaryKey / o: Key these few lines of code , and then I above
deal with java xml file that a few lines of java code will be incorrect , it is not like to write,
I ask you: how can I tell if a table has no primary key ? Where is my java code or change plus what judgment ?
------ Solution ---------------------------------------- ----
dom used to resolve references to it, then the first child element get to see is empty

tableNode.getElementsByTagName () returns a collection of child elements
------ Solution ----------------------- ---------------------
Node keyId = ((Element) tableNode.selectSingleNode("c:PrimaryKey/o:Key/@Ref"));
if(keyId != null) String id = keyId.getText();

------ For reference only ----------- ----------------------------
suggest you refer to the following PageOffice. There are many online its sample code, see Soso
------ For reference only --------------------------- ------------


judge is empty or 0 on the line but ran half are troubleshooting a problem later in
------ For reference only ---------------------------------------

this sentence seems not OK , error , and I do not judge the ref attribute is present, direct written like this:
List keyList = tableNode.selectSingleNode ("c: PrimaryKey / o: Key")
if (keyList.isEmpty () | | keyList.length == 0) {
}
else {
Node keyId = ((Element) tableNode.selectSingleNode ("c: PrimaryKey / o: Key / @ Ref"));
}
so you can play the effect , thank you ha.

没有评论:

发表评论